| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 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 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 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 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 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 | |
|
| 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 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 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 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
protected final void addMethodToCallToUncheckedList(String methodToCall) { |
| 139 | 0 | methodToCallsToNotCheckAuthorization.add(methodToCall); |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
public Set<String> getMethodToCallsToNotCheckAuthorization() { |
| 147 | 0 | return Collections.unmodifiableSet(methodToCallsToNotCheckAuthorization); |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 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 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
protected Map<String, String> getRoleQualification(UifFormBase form, String methodToCall) { |
| 173 | 0 | return new HashMap<String, String>(); |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 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 | |
|
| 189 | |
|
| 190 | |
|
| 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 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 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 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 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 | |
|
| 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 | |
|
| 267 | 0 | collectionGroup.setShowInactive(showInactive); |
| 268 | |
|
| 269 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|
| 298 | |
|
| 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 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
@RequestMapping(params = "methodToCall=back") |
| 315 | |
public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 316 | |
HttpServletRequest request, HttpServletResponse response) { |
| 317 | |
|
| 318 | |
|
| 319 | 0 | History hist = form.getFormHistory(); |
| 320 | 0 | List<HistoryEntry> histEntries = hist.getHistoryEntries(); |
| 321 | |
|
| 322 | |
|
| 323 | 0 | String histUrl = histEntries.get(histEntries.size() - 1).getUrl(); |
| 324 | |
|
| 325 | |
|
| 326 | 0 | ModelAndView modelAndView = new ModelAndView(REDIRECT_PREFIX + histUrl); |
| 327 | |
|
| 328 | 0 | return modelAndView; |
| 329 | |
} |
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 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 | |
|
| 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 | |
|
| 349 | |
|
| 350 | 0 | form.setRenderFullView(true); |
| 351 | 0 | return getUIFModelAndView(form); |
| 352 | |
} |
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 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 | |
|
| 375 | |
|
| 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 | |
|
| 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 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | 0 | String baseLookupUrl = (String) lookupParameters.get(UifParameters.BASE_LOOKUP_URL); |
| 411 | 0 | lookupParameters.remove(UifParameters.BASE_LOOKUP_URL); |
| 412 | |
|
| 413 | |
|
| 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 | |
|
| 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 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|
| 482 | 0 | AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService() |
| 483 | |
.performFieldSuggestQuery(form.getView(), queryFieldId, queryTerm, queryParameters); |
| 484 | |
|
| 485 | 0 | return queryResult; |
| 486 | |
} |
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|
| 519 | 0 | AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService() |
| 520 | |
.performFieldQuery(form.getView(), queryFieldId, queryParameters); |
| 521 | |
|
| 522 | 0 | return queryResult; |
| 523 | |
} |
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) { |
| 538 | |
|
| 539 | |
|
| 540 | 0 | urlParameters.setProperty(UifConstants.UrlParams.HISTORY, form.getFormHistory().getHistoryParameterString()); |
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 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 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 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 | |
} |