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