Coverage Report - org.kuali.rice.krad.uif.widget.QuickFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
QuickFinder
0%
0/121
0%
0/40
1.564
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation Licensed under the Educational Community
 3  
  * License, Version 1.0 (the "License"); you may not use this file except in
 4  
  * compliance with the License. You may obtain a copy of the License at
 5  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 6  
  * or agreed to in writing, software distributed under the License is
 7  
  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 8  
  * KIND, either express or implied. See the License for the specific language
 9  
  * governing permissions and limitations under the License.
 10  
  */
 11  
 package org.kuali.rice.krad.uif.widget;
 12  
 
 13  
 import org.apache.commons.lang.StringUtils;
 14  
 import org.kuali.rice.krad.bo.BusinessObjectRelationship;
 15  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 16  
 import org.kuali.rice.krad.uif.UifParameters;
 17  
 import org.kuali.rice.krad.uif.container.View;
 18  
 import org.kuali.rice.krad.uif.core.Component;
 19  
 import org.kuali.rice.krad.uif.field.ActionField;
 20  
 import org.kuali.rice.krad.uif.field.AttributeField;
 21  
 import org.kuali.rice.krad.uif.util.ViewModelUtils;
 22  
 import org.kuali.rice.krad.util.KRADUtils;
 23  
 
 24  
 import java.util.HashMap;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * Widget for navigating to a lookup from a field (called a quickfinder)
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  
 public class QuickFinder extends WidgetBase {
 34  
     private static final long serialVersionUID = 3302390972815386785L;
 35  
 
 36  
     // lookup configuration
 37  
     private String baseLookupUrl;
 38  
     private String dataObjectClassName;
 39  
     private String viewName;
 40  
 
 41  
     private String referencesToRefresh;
 42  
 
 43  
     private Map<String, String> fieldConversions;
 44  
     private Map<String, String> lookupParameters;
 45  
 
 46  
     // lookup view options
 47  
     private String readOnlySearchFields;
 48  
 
 49  
     private Boolean hideReturnLink;
 50  
     private Boolean suppressActions;
 51  
     private Boolean autoSearch;
 52  
     private Boolean lookupCriteriaEnabled;
 53  
     private Boolean supplementalActionsEnabled;
 54  
     private Boolean disableSearchButtons;
 55  
     private Boolean headerBarEnabled;
 56  
     private Boolean showMaintenanceLinks;
 57  
 
 58  
     private ActionField quickfinderActionField;
 59  
 
 60  
     public QuickFinder() {
 61  0
         super();
 62  
 
 63  0
         fieldConversions = new HashMap<String, String>();
 64  0
         lookupParameters = new HashMap<String, String>();
 65  0
     }
 66  
 
 67  
     /**
 68  
      * @see org.kuali.rice.krad.uif.widget.WidgetBase#performFinalize(org.kuali.rice.krad.uif.container.View,
 69  
      *      java.lang.Object, org.kuali.rice.krad.uif.core.Component)
 70  
      */
 71  
     @Override
 72  
     public void performFinalize(View view, Object model, Component parent) {
 73  0
         super.performFinalize(view, model, parent);
 74  
 
 75  0
         if (!isRender()) {
 76  0
             return;
 77  
         }
 78  
 
 79  0
         AttributeField field = (AttributeField) parent;
 80  
 
 81  
         // determine lookup class, field conversions and lookup parameters in
 82  
         // not set
 83  0
         if (StringUtils.isBlank(dataObjectClassName)) {
 84  0
             BusinessObjectRelationship relationship = getRelationshipForField(view, model, field);
 85  
 
 86  
             // if no relationship found cannot have a quickfinder
 87  0
             if (relationship == null) {
 88  0
                 setRender(false);
 89  0
                 return;
 90  
             }
 91  
 
 92  0
             dataObjectClassName = relationship.getRelatedClass().getName();
 93  
 
 94  0
             if ((fieldConversions == null) || fieldConversions.isEmpty()) {
 95  0
                 generateFieldConversions(field, relationship);
 96  
             }
 97  
 
 98  0
             if ((lookupParameters == null) || lookupParameters.isEmpty()) {
 99  0
                 generateLookupParameters(field, relationship);
 100  
             }
 101  
         }
 102  
 
 103  0
         quickfinderActionField.addActionParameter(UifParameters.BASE_LOOKUP_URL, baseLookupUrl);
 104  0
         quickfinderActionField.addActionParameter(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName);
 105  
 
 106  0
         if (!fieldConversions.isEmpty()) {
 107  0
             quickfinderActionField.addActionParameter(UifParameters.CONVERSION_FIELDS,
 108  
                     KRADUtils.buildMapParameterString(fieldConversions));
 109  
         }
 110  
 
 111  0
         if (!lookupParameters.isEmpty()) {
 112  0
             quickfinderActionField.addActionParameter(UifParameters.LOOKUP_PARAMETERS,
 113  
                     KRADUtils.buildMapParameterString(lookupParameters));
 114  
         }
 115  
 
 116  0
         addActionParameterIfNotNull(UifParameters.VIEW_NAME, viewName);
 117  0
         addActionParameterIfNotNull(UifParameters.READ_ONLY_FIELDS, readOnlySearchFields);
 118  0
         addActionParameterIfNotNull(UifParameters.HIDE_RETURN_LINK, hideReturnLink);
 119  0
         addActionParameterIfNotNull(UifParameters.SUPRESS_ACTIONS, suppressActions);
 120  0
         addActionParameterIfNotNull(UifParameters.REFERENCES_TO_REFRESH, referencesToRefresh);
 121  0
         addActionParameterIfNotNull(UifParameters.AUTO_SEARCH, autoSearch);
 122  0
         addActionParameterIfNotNull(UifParameters.LOOKUP_CRITERIA_ENABLED, lookupCriteriaEnabled);
 123  0
         addActionParameterIfNotNull(UifParameters.SUPPLEMENTAL_ACTIONS_ENABLED, supplementalActionsEnabled);
 124  0
         addActionParameterIfNotNull(UifParameters.DISABLE_SEARCH_BUTTONS, disableSearchButtons);
 125  0
         addActionParameterIfNotNull(UifParameters.HEADER_BAR_ENABLED, headerBarEnabled);
 126  0
         addActionParameterIfNotNull(UifParameters.SHOW_MAINTENANCE_LINKS, showMaintenanceLinks);
 127  
 
 128  
         // TODO:
 129  
         // org.kuali.rice.kns.util.FieldUtils.populateQuickfinderDefaultsForLookup(Class,
 130  
         // String, Field)
 131  0
     }
 132  
 
 133  
     protected void addActionParameterIfNotNull(String parameterName, Object parameterValue) {
 134  0
         if ((parameterValue != null) && StringUtils.isNotBlank(parameterValue.toString())) {
 135  0
             quickfinderActionField.addActionParameter(parameterName, parameterValue.toString());
 136  
         }
 137  0
     }
 138  
 
 139  
     protected BusinessObjectRelationship getRelationshipForField(View view, Object model, AttributeField field) {
 140  0
         String propertyName = field.getBindingInfo().getBindingName();
 141  
 
 142  
         // get object instance and class for parent
 143  0
         Object parentObject = ViewModelUtils.getParentObjectForMetadata(view, model, field);
 144  0
         Class<?> parentObjectClass = null;
 145  0
         if (parentObject != null) {
 146  0
             parentObjectClass = parentObject.getClass();
 147  
         }
 148  
 
 149  
         // get relationship from metadata service
 150  0
         return KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectRelationship(parentObject,
 151  
                 parentObjectClass, propertyName, "", true, true, false);
 152  
     }
 153  
 
 154  
     protected void generateFieldConversions(AttributeField field, BusinessObjectRelationship relationship) {
 155  0
         String parentObjectPath = ViewModelUtils.getParentObjectPath(field);
 156  
 
 157  0
         fieldConversions = new HashMap<String, String>();
 158  0
         for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) {
 159  0
             String fromField = entry.getValue();
 160  0
             String toField = entry.getKey();
 161  
 
 162  
             // TODO: displayedFieldnames in
 163  
             // org.kuali.rice.kns.lookup.LookupUtils.generateFieldConversions(BusinessObject,
 164  
             // String, BusinessObjectRelationship, String, List, String)
 165  
 
 166  0
             if (StringUtils.isNotBlank(parentObjectPath)) {
 167  0
                 if (field.getBindingInfo().isBindToMap()) {
 168  0
                     toField = parentObjectPath + "['" + toField + "']";
 169  
                 }
 170  
                 else {
 171  0
                     toField = parentObjectPath + "." + toField;
 172  
                 }
 173  
             }
 174  
 
 175  0
             fieldConversions.put(fromField, toField);
 176  0
         }
 177  0
     }
 178  
 
 179  
     protected void generateLookupParameters(AttributeField field, BusinessObjectRelationship relationship) {
 180  0
         String parentObjectPath = ViewModelUtils.getParentObjectPath(field);
 181  
 
 182  0
         lookupParameters = new HashMap<String, String>();
 183  0
         for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) {
 184  0
             String fromField = entry.getKey();
 185  0
             String toField = entry.getValue();
 186  
 
 187  
             // TODO: displayedFieldnames and displayedQFFieldNames in
 188  
             // generateLookupParameters(BusinessObject,
 189  
             // String, BusinessObjectRelationship, String, List, String)
 190  
 
 191  0
             if (relationship.getUserVisibleIdentifierKey() == null
 192  
                     || relationship.getUserVisibleIdentifierKey().equals(fromField)) {
 193  0
                 if (StringUtils.isNotBlank(parentObjectPath)) {
 194  0
                     if (field.getBindingInfo().isBindToMap()) {
 195  0
                         fromField = parentObjectPath + "['" + fromField + "']";
 196  
                     }
 197  
                     else {
 198  0
                         fromField = parentObjectPath + "." + fromField;
 199  
                     }
 200  
                 }
 201  
 
 202  0
                 lookupParameters.put(fromField, toField);
 203  
             }
 204  0
         }
 205  0
     }
 206  
 
 207  
     /**
 208  
      * @see org.kuali.rice.krad.uif.core.ComponentBase#getNestedComponents()
 209  
      */
 210  
     @Override
 211  
     public List<Component> getNestedComponents() {
 212  0
         List<Component> components = super.getNestedComponents();
 213  
 
 214  0
         components.add(quickfinderActionField);
 215  
 
 216  0
         return components;
 217  
     }
 218  
 
 219  
     public String getBaseLookupUrl() {
 220  0
         return this.baseLookupUrl;
 221  
     }
 222  
 
 223  
     public void setBaseLookupUrl(String baseLookupUrl) {
 224  0
         this.baseLookupUrl = baseLookupUrl;
 225  0
     }
 226  
 
 227  
     public String getDataObjectClassName() {
 228  0
         return this.dataObjectClassName;
 229  
     }
 230  
 
 231  
     public void setDataObjectClassName(String dataObjectClassName) {
 232  0
         this.dataObjectClassName = dataObjectClassName;
 233  0
     }
 234  
 
 235  
     public String getViewName() {
 236  0
         return this.viewName;
 237  
     }
 238  
 
 239  
     public void setViewName(String viewName) {
 240  0
         this.viewName = viewName;
 241  0
     }
 242  
 
 243  
     public String getReferencesToRefresh() {
 244  0
         return this.referencesToRefresh;
 245  
     }
 246  
 
 247  
     public void setReferencesToRefresh(String referencesToRefresh) {
 248  0
         this.referencesToRefresh = referencesToRefresh;
 249  0
     }
 250  
 
 251  
     public Map<String, String> getFieldConversions() {
 252  0
         return this.fieldConversions;
 253  
     }
 254  
 
 255  
     public void setFieldConversions(Map<String, String> fieldConversions) {
 256  0
         this.fieldConversions = fieldConversions;
 257  0
     }
 258  
 
 259  
     public Map<String, String> getLookupParameters() {
 260  0
         return this.lookupParameters;
 261  
     }
 262  
 
 263  
     public void setLookupParameters(Map<String, String> lookupParameters) {
 264  0
         this.lookupParameters = lookupParameters;
 265  0
     }
 266  
 
 267  
     public String getReadOnlySearchFields() {
 268  0
         return this.readOnlySearchFields;
 269  
     }
 270  
 
 271  
     public void setReadOnlySearchFields(String readOnlySearchFields) {
 272  0
         this.readOnlySearchFields = readOnlySearchFields;
 273  0
     }
 274  
 
 275  
     public Boolean getHideReturnLink() {
 276  0
         return this.hideReturnLink;
 277  
     }
 278  
 
 279  
     public void setHideReturnLink(Boolean hideReturnLink) {
 280  0
         this.hideReturnLink = hideReturnLink;
 281  0
     }
 282  
 
 283  
     public Boolean getSuppressActions() {
 284  0
         return suppressActions;
 285  
     }
 286  
 
 287  
     public void setSuppressActions(Boolean suppressActions) {
 288  0
         this.suppressActions = suppressActions;
 289  0
     }
 290  
 
 291  
     public Boolean getAutoSearch() {
 292  0
         return this.autoSearch;
 293  
     }
 294  
 
 295  
     public void setAutoSearch(Boolean autoSearch) {
 296  0
         this.autoSearch = autoSearch;
 297  0
     }
 298  
 
 299  
     public Boolean getLookupCriteriaEnabled() {
 300  0
         return this.lookupCriteriaEnabled;
 301  
     }
 302  
 
 303  
     public void setLookupCriteriaEnabled(Boolean lookupCriteriaEnabled) {
 304  0
         this.lookupCriteriaEnabled = lookupCriteriaEnabled;
 305  0
     }
 306  
 
 307  
     public Boolean getSupplementalActionsEnabled() {
 308  0
         return this.supplementalActionsEnabled;
 309  
     }
 310  
 
 311  
     public void setSupplementalActionsEnabled(Boolean supplementalActionsEnabled) {
 312  0
         this.supplementalActionsEnabled = supplementalActionsEnabled;
 313  0
     }
 314  
 
 315  
     public Boolean getDisableSearchButtons() {
 316  0
         return this.disableSearchButtons;
 317  
     }
 318  
 
 319  
     public void setDisableSearchButtons(Boolean disableSearchButtons) {
 320  0
         this.disableSearchButtons = disableSearchButtons;
 321  0
     }
 322  
 
 323  
     public Boolean getHeaderBarEnabled() {
 324  0
         return this.headerBarEnabled;
 325  
     }
 326  
 
 327  
     public void setHeaderBarEnabled(Boolean headerBarEnabled) {
 328  0
         this.headerBarEnabled = headerBarEnabled;
 329  0
     }
 330  
 
 331  
     public Boolean getShowMaintenanceLinks() {
 332  0
         return this.showMaintenanceLinks;
 333  
     }
 334  
 
 335  
     public void setShowMaintenanceLinks(Boolean showMaintenanceLinks) {
 336  0
         this.showMaintenanceLinks = showMaintenanceLinks;
 337  0
     }
 338  
 
 339  
     public ActionField getQuickfinderActionField() {
 340  0
         return this.quickfinderActionField;
 341  
     }
 342  
 
 343  
     public void setQuickfinderActionField(ActionField quickfinderActionField) {
 344  0
         this.quickfinderActionField = quickfinderActionField;
 345  0
     }
 346  
 
 347  
 }