Coverage Report - org.kuali.rice.krad.web.form.LookupForm
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupForm
0%
0/82
0%
0/26
1.833
 
 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.web.form;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.lookup.LookupUtils;
 20  
 import org.kuali.rice.krad.lookup.Lookupable;
 21  
 import org.kuali.rice.krad.uif.UifConstants.ViewType;
 22  
 import org.kuali.rice.krad.uif.view.LookupView;
 23  
 import org.kuali.rice.krad.uif.service.ViewHelperService;
 24  
 import org.kuali.rice.krad.util.KRADConstants;
 25  
 import org.kuali.rice.krad.util.KRADUtils;
 26  
 
 27  
 import javax.servlet.http.HttpServletRequest;
 28  
 import java.util.ArrayList;
 29  
 import java.util.Collection;
 30  
 import java.util.HashMap;
 31  
 import java.util.List;
 32  
 import java.util.Map;
 33  
 
 34  
 /**
 35  
  * Form class for <code>LookupView</code> screens
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  
 public class LookupForm extends UifFormBase {
 40  
     private static final long serialVersionUID = -7323484966538685327L;
 41  
 
 42  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupForm.class);
 43  
 
 44  
     private String dataObjectClassName;
 45  
     private String docNum;
 46  
     private String referencesToRefresh;
 47  
 
 48  
     private boolean multipleValuesSelect;
 49  
     private String lookupCollectionName;
 50  
 
 51  
     private Map<String, String> criteriaFields;
 52  
     private Map<String, String> fieldConversions;
 53  
 
 54  
     private boolean atLeastOneRowReturnable;
 55  
     private boolean atLeastOneRowHasActions;
 56  
 
 57  
     private Collection<?> searchResults;
 58  
 
 59  
     public LookupForm() {
 60  0
         super();
 61  
 
 62  0
         setViewTypeName(ViewType.LOOKUP);
 63  0
         atLeastOneRowReturnable = false;
 64  0
         atLeastOneRowHasActions = false;
 65  0
         multipleValuesSelect = false;
 66  
 
 67  0
         criteriaFields = new HashMap<String, String>();
 68  0
         fieldConversions = new HashMap<String, String>();
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Picks out business object name from the request to get retrieve a
 73  
      * lookupable and set properties
 74  
      */
 75  
     @Override
 76  
     public void postBind(HttpServletRequest request) {
 77  0
         super.postBind(request);
 78  
 
 79  
         try {
 80  0
             Lookupable lookupable = getLookupable();
 81  0
             if (lookupable == null) {
 82  0
                 LOG.error("Lookupable not found for view id " + getView().getId());
 83  0
                 throw new RuntimeException("Lookupable not found for view id " + getView().getId());
 84  
             }
 85  
 
 86  0
             if (StringUtils.isBlank(getDataObjectClassName())) {
 87  0
                 setDataObjectClassName(((LookupView) getView()).getDataObjectClassName().getName());
 88  
             }
 89  
 
 90  
             // init lookupable with data object class
 91  0
             Class<?> dataObjectClass = Class.forName(getDataObjectClassName());
 92  0
             lookupable.setDataObjectClass(dataObjectClass);
 93  
 
 94  
             // if showMaintenanceLinks is not already true, only show maintenance links
 95  
             // if the lookup was called from the home application view
 96  0
             if (!((LookupView) getView()).isShowMaintenanceLinks()) {
 97  
                 // TODO replace with check to history
 98  0
                 if (StringUtils.contains(getReturnLocation(), "/" + KRADConstants.PORTAL_ACTION) ||
 99  
                         StringUtils.contains(getReturnLocation(), "/index.html")) {
 100  0
                     ((LookupView) getView()).setShowMaintenanceLinks(true);
 101  
                 }
 102  
             }
 103  
 
 104  
             // populate lookup read only fields list on lookupable
 105  0
             lookupable.setReadOnlyFieldsList(getReadOnlyFieldsList());
 106  
 
 107  
             // populate field conversions list
 108  0
             if (request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER) != null) {
 109  0
                 String conversionFields = request.getParameter(KRADConstants.CONVERSION_FIELDS_PARAMETER);
 110  0
                 setFieldConversions(KRADUtils.convertStringParameterToMap(conversionFields));
 111  0
                 lookupable.setFieldConversions(getFieldConversions());
 112  
             }
 113  
 
 114  
             // perform upper casing of lookup parameters
 115  0
             Map<String, String> fieldValues = new HashMap<String, String>();
 116  0
             Map<String, String> formFields = getCriteriaFields();
 117  
 
 118  0
             if (formFields != null) {
 119  0
                 for (Map.Entry<String, String> entry : formFields.entrySet()) {
 120  
                     // check here to see if this field is a criteria element on the form
 121  0
                     fieldValues.put(entry.getKey(),
 122  
                             LookupUtils.forceUppercase(dataObjectClass, entry.getKey(), entry.getValue()));
 123  
                 }
 124  
             }
 125  
 
 126  
             // fieldValues.put(UifParameters.RETURN_FORM_KEY, getReturnFormKey());
 127  
             // fieldValues.put(UifParameters.RETURN_LOCATION, getReturnLocation());
 128  0
             if (StringUtils.isNotBlank(getDocNum())) {
 129  0
                 fieldValues.put(KRADConstants.DOC_NUM, getDocNum());
 130  
             }
 131  
 
 132  0
             this.setCriteriaFields(fieldValues);
 133  0
         } catch (ClassNotFoundException e) {
 134  0
             LOG.error("Object class " + getDataObjectClassName() + " not found");
 135  0
             throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e);
 136  0
         }
 137  0
     }
 138  
 
 139  
     public Lookupable getLookupable() {
 140  0
         ViewHelperService viewHelperService = getView().getViewHelperService();
 141  0
         if (viewHelperService == null) {
 142  0
             LOG.error("ViewHelperService is null.");
 143  0
             throw new RuntimeException("ViewHelperService is null.");
 144  
         }
 145  
 
 146  0
         if (!Lookupable.class.isAssignableFrom(viewHelperService.getClass())) {
 147  0
             LOG.error("ViewHelperService class '" + viewHelperService.getClass().getName() +
 148  
                     "' is not assignable from '" + Lookupable.class + "'");
 149  0
             throw new RuntimeException("ViewHelperService class '" + viewHelperService.getClass().getName() +
 150  
                     "' is not assignable from '" + Lookupable.class + "'");
 151  
         }
 152  
 
 153  0
         return (Lookupable) viewHelperService;
 154  
     }
 155  
 
 156  
     protected Boolean processBooleanParameter(String parameterValue) {
 157  0
         if (StringUtils.isNotBlank(parameterValue)) {
 158  0
             if ("YES".equals(parameterValue.toUpperCase())) {
 159  0
                 return Boolean.TRUE;
 160  
             }
 161  0
             return new Boolean(parameterValue);
 162  
         }
 163  0
         return null;
 164  
     }
 165  
 
 166  
     public String getDataObjectClassName() {
 167  0
         return this.dataObjectClassName;
 168  
     }
 169  
 
 170  
     public void setDataObjectClassName(String dataObjectClassName) {
 171  0
         this.dataObjectClassName = dataObjectClassName;
 172  0
     }
 173  
 
 174  
     public String getDocNum() {
 175  0
         return this.docNum;
 176  
     }
 177  
 
 178  
     public void setDocNum(String docNum) {
 179  0
         this.docNum = docNum;
 180  0
     }
 181  
 
 182  
     public String getReferencesToRefresh() {
 183  0
         return referencesToRefresh;
 184  
     }
 185  
 
 186  
     public void setReferencesToRefresh(String referencesToRefresh) {
 187  0
         this.referencesToRefresh = referencesToRefresh;
 188  0
     }
 189  
 
 190  
     /**
 191  
      * Indicates whether multiple values select should be enabled for the lookup
 192  
      *
 193  
      * <p>
 194  
      * When set to true, the select field is enabled for the lookup results group that allows the user
 195  
      * to select one or more rows for returning
 196  
      * </p>
 197  
      *
 198  
      * @return boolean true if multiple values should be enabled, false otherwise
 199  
      */
 200  
     public boolean isMultipleValuesSelect() {
 201  0
         return multipleValuesSelect;
 202  
     }
 203  
 
 204  
     /**
 205  
      * Setter for the multiple values select indicator
 206  
      *
 207  
      * @param multipleValuesSelect
 208  
      */
 209  
     public void setMultipleValuesSelect(boolean multipleValuesSelect) {
 210  0
         this.multipleValuesSelect = multipleValuesSelect;
 211  0
     }
 212  
 
 213  
     /**
 214  
      * For the case of multi-value lookup, indicates the collection that should be populated with
 215  
      * the return results
 216  
      *
 217  
      * @return String collection name (must be full binding path)
 218  
      */
 219  
     public String getLookupCollectionName() {
 220  0
         return lookupCollectionName;
 221  
     }
 222  
 
 223  
     /**
 224  
      * Setter for the name of the collection that should be populated with lookup results
 225  
      *
 226  
      * @param lookupCollectionName
 227  
      */
 228  
     public void setLookupCollectionName(String lookupCollectionName) {
 229  0
         this.lookupCollectionName = lookupCollectionName;
 230  0
     }
 231  
 
 232  
     public Map<String, String> getCriteriaFields() {
 233  0
         return this.criteriaFields;
 234  
     }
 235  
 
 236  
     public void setCriteriaFields(Map<String, String> criteriaFields) {
 237  0
         this.criteriaFields = criteriaFields;
 238  0
     }
 239  
 
 240  
     public Map<String, String> getFieldConversions() {
 241  0
         return this.fieldConversions;
 242  
     }
 243  
 
 244  
     public void setFieldConversions(Map<String, String> fieldConversions) {
 245  0
         this.fieldConversions = fieldConversions;
 246  0
     }
 247  
 
 248  
     public Collection<?> getSearchResults() {
 249  0
         return this.searchResults;
 250  
     }
 251  
 
 252  
     public void setSearchResults(Collection<?> searchResults) {
 253  0
         this.searchResults = searchResults;
 254  0
     }
 255  
 
 256  
     public boolean isAtLeastOneRowReturnable() {
 257  0
         return atLeastOneRowReturnable;
 258  
     }
 259  
 
 260  
     public void setAtLeastOneRowReturnable(boolean atLeastOneRowReturnable) {
 261  0
         this.atLeastOneRowReturnable = atLeastOneRowReturnable;
 262  0
     }
 263  
 
 264  
     public boolean isAtLeastOneRowHasActions() {
 265  0
         return atLeastOneRowHasActions;
 266  
     }
 267  
 
 268  
     public void setAtLeastOneRowHasActions(boolean atLeastOneRowHasActions) {
 269  0
         this.atLeastOneRowHasActions = atLeastOneRowHasActions;
 270  0
     }
 271  
 }