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