Coverage Report - org.kuali.rice.krad.uif.widget.DirectInquiry
 
Classes in this File Line Coverage Branch Coverage Complexity
DirectInquiry
0%
0/51
0%
0/20
2.667
 
 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.krad.uif.widget;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.uif.UifConstants;
 20  
 import org.kuali.rice.krad.uif.UifParameters;
 21  
 import org.kuali.rice.krad.uif.field.InputField;
 22  
 import org.kuali.rice.krad.uif.view.View;
 23  
 import org.kuali.rice.krad.uif.component.BindingInfo;
 24  
 import org.kuali.rice.krad.uif.component.Component;
 25  
 import org.kuali.rice.krad.uif.field.ActionField;
 26  
 import org.kuali.rice.krad.util.UrlFactory;
 27  
 
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 import java.util.Map.Entry;
 31  
 import java.util.Properties;
 32  
 
 33  
 /**
 34  
  * Widget for rendering an Direct Inquiry link icon next to a input field
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  
 public class DirectInquiry extends Inquiry {
 39  
     private static final long serialVersionUID = -2490979579285984314L;
 40  
     
 41  
     private ActionField directInquiryActionField;
 42  
 
 43  
     private boolean adjustInquiryParameters;
 44  
     private BindingInfo fieldBindingInfo;
 45  
 
 46  
     public DirectInquiry() {
 47  0
         super();
 48  
 
 49  0
         adjustInquiryParameters = false;
 50  0
     }
 51  
 
 52  
     /**
 53  
      * @see org.kuali.rice.krad.uif.widget.WidgetBase#performFinalize(org.kuali.rice.krad.uif.view.View,
 54  
      *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
 55  
      */
 56  
     @Override
 57  
     public void performFinalize(View view, Object model, Component parent) {
 58  0
         super.performFinalize(view, model, parent);
 59  
 
 60  
         // only set inquiry if enabled
 61  0
         if (!isRender() || isReadOnly()) {
 62  0
             return;
 63  
         }
 64  
 
 65  
         // set render to false until we find an inquiry class
 66  0
         setRender(false);
 67  
 
 68  0
         InputField field = (InputField) parent;
 69  
 
 70  
         // determine whether inquiry parameters will need adjusted
 71  0
         if (StringUtils.isBlank(getDataObjectClassName())
 72  
                 || (getInquiryParameters() == null)
 73  
                 || getInquiryParameters().isEmpty()) {
 74  
             // if inquiry parameters not given, they will not be adjusted by super
 75  0
             adjustInquiryParameters = true;
 76  0
             fieldBindingInfo = field.getBindingInfo();
 77  
         }
 78  
 
 79  0
             setupLink(view, model, field);
 80  0
     }
 81  
 
 82  
     /**
 83  
      * Builds the inquiry link and onclick script based on the given inquiry class and parameters
 84  
      * 
 85  
      * @param dataObject
 86  
      *            - parent object that contains the data (used to pull inquiry
 87  
      *            parameters)
 88  
      * @param propertyName
 89  
      *            - name of the property the inquiry is set on
 90  
      * @param inquiryObjectClass
 91  
      *            - class of the object the inquiry should point to
 92  
      * @param inquiryParms
 93  
      *            - map of key field mappings for the inquiry
 94  
      */
 95  
         public void buildInquiryLink(Object dataObject, String propertyName,
 96  
                         Class<?> inquiryObjectClass, Map<String, String> inquiryParms) {
 97  0
                 Properties urlParameters = new Properties();
 98  
 
 99  0
                 urlParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
 100  
                                 inquiryObjectClass.getName());
 101  0
                 urlParameters.put(UifParameters.METHOD_TO_CALL,
 102  
                                 UifConstants.MethodToCallNames.START);
 103  
 
 104  
                 // Direct inquiry
 105  0
                 String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(),
 106  
                                 urlParameters);
 107  0
                 StringBuilder paramMapString = new StringBuilder();
 108  
 
 109  
                 // Check if lightbox is set. Get lightbox options.
 110  0
                 String lightBoxOptions = "";
 111  0
                 boolean lightBoxShow = directInquiryActionField.getLightBoxDirectInquiry() != null;
 112  0
                 if (lightBoxShow) {
 113  0
                         lightBoxOptions = directInquiryActionField.getLightBoxDirectInquiry()
 114  
                                         .getComponentOptionsJSString();
 115  
                 }
 116  
 
 117  
                 // Build parameter string using the actual names of the fields as on the
 118  
                 // html page
 119  0
         for (Entry<String, String> inquiryParameter : inquiryParms.entrySet()) {
 120  0
             String inquiryParameterFrom = inquiryParameter.getKey();
 121  0
             if (adjustInquiryParameters && (fieldBindingInfo != null)) {
 122  0
                 inquiryParameterFrom = fieldBindingInfo.getPropertyAdjustedBindingPath(inquiryParameterFrom);
 123  
             }
 124  0
             paramMapString.append(inquiryParameterFrom);
 125  0
             paramMapString.append(":");
 126  0
             paramMapString.append(inquiryParameter.getValue());
 127  0
             paramMapString.append(",");
 128  0
         }
 129  0
                 paramMapString.deleteCharAt(paramMapString.length() - 1);
 130  
 
 131  
                 // Create onlick script to open the inquiry window on the click event
 132  
                 // of the direct inquiry
 133  0
                 StringBuilder onClickScript = new StringBuilder("showDirectInquiry(\"");
 134  0
                 onClickScript.append(inquiryUrl);
 135  0
                 onClickScript.append("\", \"");
 136  0
                 onClickScript.append(paramMapString);
 137  0
                 onClickScript.append("\", ");
 138  0
                 onClickScript.append(lightBoxShow);
 139  0
                 onClickScript.append(", ");
 140  0
                 onClickScript.append(lightBoxOptions);
 141  0
                 onClickScript.append(");");
 142  
 
 143  0
                 directInquiryActionField.setBlockValidateDirty(true);
 144  0
                 directInquiryActionField.setClientSideJs(onClickScript.toString());
 145  
 
 146  0
                 setRender(true);
 147  0
         }
 148  
 
 149  
     /**
 150  
      * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
 151  
      */
 152  
     @Override
 153  
     public List<Component> getComponentsForLifecycle() {
 154  0
         List<Component> components = super.getComponentsForLifecycle();
 155  
 
 156  0
         components.add(directInquiryActionField);
 157  
 
 158  0
         return components;
 159  
     }        
 160  
         
 161  
         /**
 162  
          * @return the directInquiryActionField
 163  
          */
 164  
         public ActionField getDirectInquiryActionField() {
 165  0
                 return this.directInquiryActionField;
 166  
         }
 167  
 
 168  
         /**
 169  
          * @param directInquiryActionField the directInquiryActionField to set
 170  
          */
 171  
         public void setDirectInquiryActionField(ActionField directInquiryActionField) {
 172  0
                 this.directInquiryActionField = directInquiryActionField;
 173  0
         }
 174  
 
 175  
 }