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