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