Coverage Report - org.kuali.rice.krad.web.controller.UifControllerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
UifControllerBase
0%
0/165
0%
0/58
2.72
 
 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.web.controller;
 12  
 
 13  
 import org.apache.commons.lang.StringUtils;
 14  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 15  
 import org.kuali.rice.core.web.format.BooleanFormatter;
 16  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 17  
 import org.kuali.rice.kim.util.KimConstants;
 18  
 import org.kuali.rice.krad.UserSession;
 19  
 import org.kuali.rice.krad.exception.AuthorizationException;
 20  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 21  
 import org.kuali.rice.krad.service.ModuleService;
 22  
 import org.kuali.rice.krad.service.SessionDocumentService;
 23  
 import org.kuali.rice.krad.uif.UifConstants;
 24  
 import org.kuali.rice.krad.uif.UifParameters;
 25  
 import org.kuali.rice.krad.uif.UifPropertyPaths;
 26  
 import org.kuali.rice.krad.uif.container.CollectionGroup;
 27  
 import org.kuali.rice.krad.uif.container.View;
 28  
 import org.kuali.rice.krad.uif.core.Component;
 29  
 import org.kuali.rice.krad.uif.field.AttributeQueryResult;
 30  
 import org.kuali.rice.krad.uif.history.History;
 31  
 import org.kuali.rice.krad.uif.history.HistoryEntry;
 32  
 import org.kuali.rice.krad.uif.service.ViewService;
 33  
 import org.kuali.rice.krad.uif.util.ComponentFactory;
 34  
 import org.kuali.rice.krad.uif.util.LookupInquiryUtils;
 35  
 import org.kuali.rice.krad.uif.util.UifWebUtils;
 36  
 import org.kuali.rice.krad.util.GlobalVariables;
 37  
 import org.kuali.rice.krad.util.KRADConstants;
 38  
 import org.kuali.rice.krad.util.KRADUtils;
 39  
 import org.kuali.rice.krad.util.UrlFactory;
 40  
 import org.kuali.rice.krad.web.form.UifFormBase;
 41  
 import org.springframework.validation.BindingResult;
 42  
 import org.springframework.web.bind.annotation.ModelAttribute;
 43  
 import org.springframework.web.bind.annotation.RequestMapping;
 44  
 import org.springframework.web.bind.annotation.RequestMethod;
 45  
 import org.springframework.web.bind.annotation.ResponseBody;
 46  
 import org.springframework.web.servlet.ModelAndView;
 47  
 
 48  
 import javax.servlet.http.HttpServletRequest;
 49  
 import javax.servlet.http.HttpServletResponse;
 50  
 import java.util.Collections;
 51  
 import java.util.Enumeration;
 52  
 import java.util.HashMap;
 53  
 import java.util.HashSet;
 54  
 import java.util.List;
 55  
 import java.util.Map;
 56  
 import java.util.Map.Entry;
 57  
 import java.util.Properties;
 58  
 import java.util.Set;
 59  
 
 60  
 /**
 61  
  * Base controller class for views within the KRAD User Interface Framework
 62  
  *
 63  
  * Provides common methods such as:
 64  
  *
 65  
  * <ul>
 66  
  * <li>Authorization methods such as method to call check</li>
 67  
  * <li>Preparing the View instance and setup in the returned
 68  
  * <code>ModelAndView</code></li>
 69  
  * </ul>
 70  
  *
 71  
  * All subclass controller methods after processing should call one of the
 72  
  * #getUIFModelAndView methods to setup the <code>View</code> and return the
 73  
  * <code>ModelAndView</code> instance.
 74  
  *
 75  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 76  
  */
 77  0
 public abstract class UifControllerBase {
 78  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifControllerBase.class);
 79  
 
 80  
     protected static final String REDIRECT_PREFIX = "redirect:";
 81  
 
 82  
     private SessionDocumentService sessionDocumentService;
 83  
 
 84  
     /**
 85  
      * Create/obtain the model(form) object before it is passed
 86  
      * to the Binder/BeanWrapper. This method is not intended to be overridden
 87  
      * by client applications as it handles framework setup and session
 88  
      * maintenance. Clients should override createIntialForm() instead when they
 89  
      * need custom form initialization.
 90  
      */
 91  
     @ModelAttribute(value = "KualiForm")
 92  
     public UifFormBase initForm(HttpServletRequest request) {
 93  0
         UifFormBase form = null;
 94  0
         String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
 95  0
         String documentNumber = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER);
 96  
 
 97  0
         if (StringUtils.isNotBlank(formKeyParam)) {
 98  0
             form = (UifFormBase) request.getSession().getAttribute(formKeyParam);
 99  
 
 100  
             // retreive from db if form not in session
 101  0
             if (form == null) {
 102  0
                 UserSession userSession = (UserSession) request.getSession()
 103  
                         .getAttribute(KRADConstants.USER_SESSION_KEY);
 104  0
                 form = getSessionDocumentService().getDocumentForm(documentNumber, formKeyParam, userSession,
 105  
                         request.getRemoteAddr());
 106  0
             }
 107  
         } else {
 108  0
             form = createInitialForm(request);
 109  
         }
 110  
 
 111  0
         return form;
 112  
     }
 113  
 
 114  
     /**
 115  
      * Called to create a new model(form) object when
 116  
      * necessary. This usually occurs on the initial request in a conversation
 117  
      * (when the model is not present in the session). This method must be
 118  
      * overridden when extending a controller and using a different form type
 119  
      * than the superclass.
 120  
      */
 121  
     protected abstract UifFormBase createInitialForm(HttpServletRequest request);
 122  
 
 123  0
     private Set<String> methodToCallsToNotCheckAuthorization = new HashSet<String>();
 124  
     {
 125  0
         methodToCallsToNotCheckAuthorization.add("performLookup");
 126  0
         methodToCallsToNotCheckAuthorization.add("performQuestion");
 127  0
         methodToCallsToNotCheckAuthorization.add("performQuestionWithInput");
 128  0
         methodToCallsToNotCheckAuthorization.add("performQuestionWithInputAgainBecauseOfErrors");
 129  0
         methodToCallsToNotCheckAuthorization.add("performQuestionWithoutInput");
 130  0
         methodToCallsToNotCheckAuthorization.add("performWorkgroupLookup");
 131  0
     }
 132  
 
 133  
     /**
 134  
      * Use to add a methodToCall to the a list which will not have authorization
 135  
      * checks. This assumes that the call will be redirected (as in the case of
 136  
      * a lookup) that will perform the authorization.
 137  
      */
 138  
     protected final void addMethodToCallToUncheckedList(String methodToCall) {
 139  0
         methodToCallsToNotCheckAuthorization.add(methodToCall);
 140  0
     }
 141  
 
 142  
     /**
 143  
      * Returns an immutable Set of methodToCall parameters that should not be
 144  
      * checked for authorization.
 145  
      */
 146  
     public Set<String> getMethodToCallsToNotCheckAuthorization() {
 147  0
         return Collections.unmodifiableSet(methodToCallsToNotCheckAuthorization);
 148  
     }
 149  
 
 150  
     /**
 151  
      * Override this method to provide controller class-level access controls to
 152  
      * the application.
 153  
      */
 154  
     public void checkAuthorization(UifFormBase form, String methodToCall) throws AuthorizationException {
 155  0
         String principalId = GlobalVariables.getUserSession().getPrincipalId();
 156  0
         Map<String, String> roleQualifier = new HashMap<String, String>(getRoleQualification(form, methodToCall));
 157  0
         Map<String, String> permissionDetails = KRADUtils.getNamespaceAndActionClass(this.getClass());
 158  
 
 159  0
         if (!KimApiServiceLocator.getPermissionService()
 160  
                 .isAuthorizedByTemplateName(principalId, KRADConstants.KRAD_NAMESPACE,
 161  
                         KimConstants.PermissionTemplateNames.USE_SCREEN, permissionDetails,
 162  
                         roleQualifier)) {
 163  0
             throw new AuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(),
 164  
                     methodToCall, this.getClass().getSimpleName());
 165  
         }
 166  0
     }
 167  
 
 168  
     /**
 169  
      * Override this method to add data from the form for role qualification in
 170  
      * the authorization check
 171  
      */
 172  
     protected Map<String, String> getRoleQualification(UifFormBase form, String methodToCall) {
 173  0
         return new HashMap<String, String>();
 174  
     }
 175  
 
 176  
     /**
 177  
      * Initial method called when requesting a new view instance which forwards
 178  
      * the view for rendering
 179  
      */
 180  
     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
 181  
     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 182  
             HttpServletRequest request, HttpServletResponse response) {
 183  
 
 184  0
         return getUIFModelAndView(form);
 185  
     }
 186  
 
 187  
     /**
 188  
      * Called by the add line action for a new collection line. Method
 189  
      * determines which collection the add action was selected for and invokes
 190  
      * the view helper service to add the line
 191  
      */
 192  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
 193  
     public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
 194  
             HttpServletRequest request, HttpServletResponse response) {
 195  
 
 196  0
         String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
 197  0
         if (StringUtils.isBlank(selectedCollectionPath)) {
 198  0
             throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
 199  
         }
 200  
 
 201  0
         View view = uifForm.getPreviousView();
 202  0
         view.getViewHelperService().processCollectionAddLine(view, uifForm, selectedCollectionPath);
 203  
 
 204  0
         return updateComponent(uifForm, result, request, response);
 205  
     }
 206  
 
 207  
     /**
 208  
      * Called by the delete line action for a model collection. Method
 209  
      * determines which collection the action was selected for and the line
 210  
      * index that should be removed, then invokes the view helper service to
 211  
      * process the action
 212  
      */
 213  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine")
 214  
     public ModelAndView deleteLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
 215  
             HttpServletRequest request, HttpServletResponse response) {
 216  
 
 217  0
         String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
 218  0
         if (StringUtils.isBlank(selectedCollectionPath)) {
 219  0
             throw new RuntimeException("Selected collection was not set for delete line action, cannot delete line");
 220  
         }
 221  
 
 222  0
         int selectedLineIndex = -1;
 223  0
         String selectedLine = uifForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
 224  0
         if (StringUtils.isNotBlank(selectedLine)) {
 225  0
             selectedLineIndex = Integer.parseInt(selectedLine);
 226  
         }
 227  
 
 228  0
         if (selectedLineIndex == -1) {
 229  0
             throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line");
 230  
         }
 231  
 
 232  0
         View view = uifForm.getPreviousView();
 233  0
         view.getViewHelperService().processCollectionDeleteLine(view, uifForm, selectedCollectionPath,
 234  
                 selectedLineIndex);
 235  
 
 236  0
         return updateComponent(uifForm, result, request, response);
 237  
     }
 238  
 
 239  
     /**
 240  
      * Invoked to toggle the show inactive indicator on the selected collection group and then
 241  
      * rerun the component lifecycle and rendering based on the updated indicator and form data
 242  
      *
 243  
      * @param request - request object that should contain the request component id (for the collection group)
 244  
      * and the show inactive indicator value
 245  
      */
 246  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=toggleInactiveRecordDisplay")
 247  
     public ModelAndView toggleInactiveRecordDisplay(@ModelAttribute("KualiForm") UifFormBase uifForm,
 248  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 249  0
         String collectionGroupId = request.getParameter(UifParameters.REQUESTED_COMPONENT_ID);
 250  0
         if (StringUtils.isBlank(collectionGroupId)) {
 251  0
             throw new RuntimeException(
 252  
                     "Collection group id to update for inactive record display not found in request");
 253  
         }
 254  
 
 255  0
         String showInactiveStr = request.getParameter(UifParameters.SHOW_INACTIVE_RECORDS);
 256  0
         Boolean showInactive = false;
 257  0
         if (StringUtils.isNotBlank(showInactiveStr)) {
 258  
             // TODO: should use property editors once we have util class
 259  0
             showInactive = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(showInactiveStr);
 260  
         } else {
 261  0
             throw new RuntimeException("Show inactive records flag not found in request");
 262  
         }
 263  
 
 264  0
         CollectionGroup collectionGroup = (CollectionGroup) ComponentFactory.getComponentById(uifForm, collectionGroupId);
 265  
 
 266  
         // update inactive flag on group
 267  0
         collectionGroup.setShowInactive(showInactive);
 268  
 
 269  
         // run lifecycle and update in view
 270  0
         uifForm.getView().getViewHelperService().performComponentLifecycle(uifForm, collectionGroup, collectionGroupId);
 271  0
         uifForm.getView().getViewIndex().indexComponent(collectionGroup);
 272  
 
 273  0
         return UifWebUtils.getComponentModelAndView(collectionGroup, uifForm);
 274  
     }
 275  
 
 276  
     /**
 277  
      * Just returns as if return with no value was selected.
 278  
      */
 279  
     @RequestMapping(params = "methodToCall=cancel")
 280  
     public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 281  
             HttpServletRequest request, HttpServletResponse response) {
 282  0
         return close(form, result, request, response);
 283  
     }
 284  
 
 285  
     /**
 286  
      * Just returns as if return with no value was selected.
 287  
      */
 288  
     @RequestMapping(params = "methodToCall=close")
 289  
     public ModelAndView close(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 290  
             HttpServletRequest request, HttpServletResponse response) {
 291  0
         Properties props = new Properties();
 292  0
         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
 293  0
         if (StringUtils.isNotBlank(form.getReturnFormKey())) {
 294  0
             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
 295  
         }
 296  
 
 297  
         // TODO this needs setup for lightbox and possible home location
 298  
         // property
 299  0
         String returnUrl = form.getReturnLocation();
 300  0
         if (StringUtils.isBlank(returnUrl)) {
 301  0
             returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY);
 302  
         }
 303  
 
 304  0
         return performRedirect(form, returnUrl, props);
 305  
     }
 306  
 
 307  
     /**
 308  
      * Invoked to navigate back one page in history. This will be the same as clicking on the bread
 309  
      * crumbs. This action should only be allowed if there are at least one history entry
 310  
      * (!formHistory.historyEntries.empty).
 311  
      * 
 312  
      * @param form - form object that should contain the history object
 313  
      */
 314  
     @RequestMapping(params = "methodToCall=back")
 315  
     public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 316  
             HttpServletRequest request, HttpServletResponse response) {
 317  
 
 318  
         // Get the history from the form
 319  0
         History hist = form.getFormHistory();
 320  0
         List<HistoryEntry> histEntries = hist.getHistoryEntries();
 321  
 
 322  
         // Get the previous page url.
 323  0
         String histUrl = histEntries.get(histEntries.size() - 1).getUrl();
 324  
 
 325  
         // Redirect to the previous page
 326  0
         ModelAndView modelAndView = new ModelAndView(REDIRECT_PREFIX + histUrl);
 327  
 
 328  0
         return modelAndView;
 329  
     }  
 330  
 
 331  
     /**
 332  
      * Handles menu navigation between view pages
 333  
      */
 334  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
 335  
     public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 336  
             HttpServletRequest request, HttpServletResponse response) {
 337  0
         String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
 338  
 
 339  
         // only refreshing page
 340  0
         form.setRenderFullView(false);
 341  
 
 342  0
         return getUIFModelAndView(form, form.getViewId(), pageId);
 343  
     }
 344  
 
 345  
     @RequestMapping(params = "methodToCall=refresh")
 346  
     public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 347  
             HttpServletRequest request, HttpServletResponse response) throws Exception {
 348  
         // TODO: this code still needs ported with whatever we are supposed
 349  
         // to do on refresh
 350  0
         form.setRenderFullView(true);
 351  0
         return getUIFModelAndView(form);
 352  
     }
 353  
 
 354  
     /**
 355  
      * Updates the current component by retrieving a fresh copy from the dictionary,
 356  
      * running its component lifecycle, and returning it
 357  
      *
 358  
      * @param request - the request must contain reqComponentId that specifies the component to retrieve
 359  
      */
 360  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=updateComponent")
 361  
     public ModelAndView updateComponent(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 362  
             HttpServletRequest request, HttpServletResponse response) {
 363  0
         String requestedComponentId = request.getParameter(UifParameters.REQUESTED_COMPONENT_ID);
 364  0
         if (StringUtils.isBlank(requestedComponentId)) {
 365  0
             throw new RuntimeException("Requested component id for update not found in request");
 366  
         }
 367  
 
 368  0
         Component comp = ComponentFactory.getComponentByIdWithLifecycle(form, requestedComponentId);
 369  
 
 370  0
         return UifWebUtils.getComponentModelAndView(comp, form);
 371  
     }
 372  
 
 373  
     /**
 374  
      * Builds up a URL to the lookup view based on the given post action
 375  
      * parameters and redirects
 376  
      */
 377  
     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=performLookup")
 378  
     public ModelAndView performLookup(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 379  
             HttpServletRequest request, HttpServletResponse response) {
 380  0
         Properties lookupParameters = form.getActionParametersAsProperties();
 381  
 
 382  0
         String lookupObjectClassName = (String) lookupParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME);
 383  0
         Class<?> lookupObjectClass = null;
 384  
         try {
 385  0
             lookupObjectClass = Class.forName(lookupObjectClassName);
 386  0
         } catch (ClassNotFoundException e) {
 387  0
             LOG.error("Unable to get class for name: " + lookupObjectClassName);
 388  0
             throw new RuntimeException("Unable to get class for name: " + lookupObjectClassName, e);
 389  0
         }
 390  
 
 391  
         // get form values for the lookup parameter fields
 392  0
         String lookupParameterString = (String) lookupParameters.get(UifParameters.LOOKUP_PARAMETERS);
 393  0
         if (lookupParameterString != null) {
 394  0
             Map<String, String> lookupParameterFields = KRADUtils.getMapFromParameterString(lookupParameterString);
 395  0
             for (Entry<String, String> lookupParameter : lookupParameterFields.entrySet()) {
 396  0
                 String lookupParameterValue = LookupInquiryUtils.retrieveLookupParameterValue(form, request,
 397  
                         lookupObjectClass, lookupParameter.getValue(), lookupParameter.getKey());
 398  
 
 399  0
                 if (StringUtils.isNotBlank(lookupParameterValue)) {
 400  0
                     lookupParameters.put(UifPropertyPaths.CRITERIA_FIELDS + "['" + lookupParameter.getValue() + "']",
 401  
                             lookupParameterValue);
 402  
                 }
 403  0
             }
 404  
         }
 405  
 
 406  
         // TODO: lookup anchors and doc number?
 407  
 
 408  
         // TODO: multi-value lookup requests
 409  
 
 410  0
         String baseLookupUrl = (String) lookupParameters.get(UifParameters.BASE_LOOKUP_URL);
 411  0
         lookupParameters.remove(UifParameters.BASE_LOOKUP_URL);
 412  
 
 413  
         // set lookup method to call
 414  0
         lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
 415  0
         String autoSearchString = (String) lookupParameters.get(UifParameters.AUTO_SEARCH);
 416  0
         if (Boolean.parseBoolean(autoSearchString)) {
 417  0
             lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.SEARCH);
 418  
         }
 419  
 
 420  0
         lookupParameters.put(UifParameters.RETURN_LOCATION, form.getFormPostUrl());
 421  0
         lookupParameters.put(UifParameters.RETURN_FORM_KEY, form.getFormKey());
 422  
 
 423  
         // special check for external object classes
 424  0
         if (lookupObjectClass != null) {
 425  0
             ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService()
 426  
                     .getResponsibleModuleService(lookupObjectClass);
 427  0
             if (responsibleModuleService != null && responsibleModuleService.isExternalizable(lookupObjectClass)) {
 428  0
                 Map<String, String> parameterMap = new HashMap<String, String>();
 429  0
                 Enumeration<Object> e = lookupParameters.keys();
 430  0
                 while (e.hasMoreElements()) {
 431  0
                     String paramName = (String) e.nextElement();
 432  0
                     parameterMap.put(paramName, lookupParameters.getProperty(paramName));
 433  0
                 }
 434  
 
 435  0
                 String lookupUrl = responsibleModuleService.getExternalizableBusinessObjectLookupUrl(lookupObjectClass,
 436  
                         parameterMap);
 437  0
                 return performRedirect(form, lookupUrl, new Properties());
 438  
             }
 439  
         }
 440  
 
 441  0
         return performRedirect(form, baseLookupUrl, lookupParameters);
 442  
     }
 443  
 
 444  
     /**
 445  
      * Invoked to provide the options for a suggest widget. The valid options are retrieved by the associated
 446  
      * <code>AttributeQuery</code> for the field containing the suggest widget. The controller method picks
 447  
      * out the query parameters from the request and calls <code>AttributeQueryService</code> to perform the
 448  
      * suggest query and prepare the result object that will be exposed with JSON
 449  
      */
 450  
     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest")
 451  
     public @ResponseBody AttributeQueryResult performFieldSuggest(@ModelAttribute("KualiForm") UifFormBase form,
 452  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 453  
 
 454  
         // retrieve query fields from request
 455  0
         Map<String, String> queryParameters = new HashMap<String, String>();
 456  0
         for (Object parameterName : request.getParameterMap().keySet()) {
 457  0
             if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) {
 458  0
                 String fieldName =
 459  
                         StringUtils.substringAfter(parameterName.toString(), UifParameters.QUERY_PARAMETER + ".");
 460  0
                 String fieldValue = request.getParameter(parameterName.toString());
 461  0
                 queryParameters.put(fieldName, fieldValue);
 462  0
             }
 463  
         }
 464  
 
 465  
         // retrieve id for field to perform query for
 466  0
         String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID);
 467  0
         if (StringUtils.isBlank(queryFieldId)) {
 468  0
             throw new RuntimeException(
 469  
                     "Unable to find id for field to perform query on under request parameter name: " +
 470  
                             UifParameters.QUERY_FIELD_ID);
 471  
         }
 472  
 
 473  
         // get the field term to match
 474  0
         String queryTerm = request.getParameter(UifParameters.QUERY_TERM);
 475  0
         if (StringUtils.isBlank(queryTerm)) {
 476  0
             throw new RuntimeException(
 477  
                     "Unable to find id for query term value for attribute query on under request parameter name: " +
 478  
                             UifParameters.QUERY_TERM);
 479  
         }
 480  
 
 481  
         // invoke attribute query service to perform the query
 482  0
         AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService()
 483  
                 .performFieldSuggestQuery(form.getView(), queryFieldId, queryTerm, queryParameters);
 484  
 
 485  0
         return queryResult;
 486  
     }
 487  
 
 488  
     /**
 489  
      * Invoked to execute the <code>AttributeQuery</code> associated with a field given the query parameters
 490  
      * found in the request. This controller method picks out the query parameters from the request and calls
 491  
      * <code>AttributeQueryService</code> to perform the field query and prepare the result object
 492  
      * that will be exposed with JSON. The result is then used to update field values in the UI with client
 493  
      * script.
 494  
      */
 495  
     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldQuery")
 496  
     public @ResponseBody AttributeQueryResult performFieldQuery(@ModelAttribute("KualiForm") UifFormBase form,
 497  
             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
 498  
 
 499  
         // retrieve query fields from request
 500  0
         Map<String, String> queryParameters = new HashMap<String, String>();
 501  0
         for (Object parameterName : request.getParameterMap().keySet()) {
 502  0
             if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) {
 503  0
                 String fieldName =
 504  
                         StringUtils.substringAfter(parameterName.toString(), UifParameters.QUERY_PARAMETER + ".");
 505  0
                 String fieldValue = request.getParameter(parameterName.toString());
 506  0
                 queryParameters.put(fieldName, fieldValue);
 507  0
             }
 508  
         }
 509  
 
 510  
         // retrieve id for field to perform query for
 511  0
         String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID);
 512  0
         if (StringUtils.isBlank(queryFieldId)) {
 513  0
             throw new RuntimeException(
 514  
                     "Unable to find id for field to perform query on under request parameter name: " +
 515  
                             UifParameters.QUERY_FIELD_ID);
 516  
         }
 517  
 
 518  
         // invoke attribute query service to perform the query
 519  0
         AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService()
 520  
                 .performFieldQuery(form.getView(), queryFieldId, queryParameters);
 521  
 
 522  0
         return queryResult;
 523  
     }
 524  
 
 525  
     /**
 526  
      * Builds a <code>ModelAndView</code> instance configured to redirect to the
 527  
      * URL formed by joining the base URL with the given URL parameters
 528  
      *
 529  
      * @param form
 530  
      *            - current form instance
 531  
      * @param baseUrl
 532  
      *            - base url to redirect to
 533  
      * @param urlParameters
 534  
      *            - properties containing key/value pairs for the url parameters
 535  
      * @return ModelAndView configured to redirect to the given URL
 536  
      */
 537  
     protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) {
 538  
         // On post redirects we need to make sure we are sending the history
 539  
         // forward:
 540  0
         urlParameters.setProperty(UifConstants.UrlParams.HISTORY, form.getFormHistory().getHistoryParameterString());
 541  
 
 542  
         // If this is an Ajax call only return the redirectURL view with the URL
 543  
         // set this is to avoid automatic redirect when using light boxes
 544  0
         if (urlParameters.get("ajaxCall") != null && urlParameters.get("ajaxCall").equals("true")) {
 545  0
             urlParameters.remove("ajaxCall");
 546  0
             String redirectUrl = UrlFactory.parameterizeUrl(baseUrl, urlParameters);
 547  
 
 548  0
             ModelAndView modelAndView = new ModelAndView("redirectURL");
 549  0
             modelAndView.addObject("redirectUrl", redirectUrl);
 550  0
             return modelAndView;
 551  
         }
 552  
 
 553  0
         String redirectUrl = UrlFactory.parameterizeUrl(baseUrl, urlParameters);
 554  0
         ModelAndView modelAndView = new ModelAndView(REDIRECT_PREFIX + redirectUrl);
 555  
 
 556  0
         return modelAndView;
 557  
     }
 558  
 
 559  
     protected ModelAndView getUIFModelAndView(UifFormBase form) {
 560  0
         return getUIFModelAndView(form, form.getViewId(), form.getPageId());
 561  
     }
 562  
 
 563  
     protected ModelAndView getUIFModelAndView(UifFormBase form, String viewId) {
 564  0
         return getUIFModelAndView(form, viewId, "");
 565  
     }
 566  
 
 567  
     /**
 568  
      * Configures the <code>ModelAndView</code> instance containing the form
 569  
      * data and pointing to the UIF generic spring view
 570  
      *
 571  
      * @param form
 572  
      *            - Form instance containing the model data
 573  
      * @param viewId
 574  
      *            - Id of the View to return
 575  
      * @param pageId
 576  
      *            - Id of the page within the view that should be rendered, can
 577  
      *            be left blank in which the current or default page is rendered
 578  
      * @return ModelAndView object with the contained form
 579  
      */
 580  
     protected ModelAndView getUIFModelAndView(UifFormBase form, String viewId, String pageId) {
 581  0
         return UifWebUtils.getUIFModelAndView(form, viewId, pageId);
 582  
     }
 583  
 
 584  
     protected ViewService getViewService() {
 585  0
         return KRADServiceLocatorWeb.getViewService();
 586  
     }
 587  
 
 588  
     public SessionDocumentService getSessionDocumentService() {
 589  0
         return KRADServiceLocatorWeb.getSessionDocumentService();
 590  
     }
 591  
 
 592  
 }