1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.web.controller;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.uif.UifParameters;
22 import org.kuali.rice.krad.uif.field.AttributeQueryResult;
23 import org.kuali.rice.krad.web.form.UifFormBase;
24 import org.springframework.validation.BindingResult;
25 import org.springframework.web.bind.annotation.ModelAttribute;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestMethod;
28 import org.springframework.web.bind.annotation.ResponseBody;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.util.HashMap;
33 import java.util.Map;
34
35
36
37
38
39
40 public abstract class KsUifControllerBase extends UifControllerBase {
41
42
43
44
45
46
47
48
49 @Override
50 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest")
51 public
52 @ResponseBody
53 AttributeQueryResult performFieldSuggest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
54 HttpServletRequest request, HttpServletResponse response) {
55
56
57 Map<String, String> queryParameters = new HashMap<String, String>();
58 for (Object parameterName : request.getParameterMap().keySet()) {
59 if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) {
60 String fieldName = StringUtils.substringAfter(parameterName.toString(),
61 UifParameters.QUERY_PARAMETER + ".");
62 String fieldValue = request.getParameter(parameterName.toString());
63 queryParameters.put(fieldName, fieldValue);
64 }
65 }
66
67
68 String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID);
69 if (StringUtils.isBlank(queryFieldId)) {
70 throw new RuntimeException("Unable to find id for field to perform query on under request parameter name: "
71 + UifParameters.QUERY_FIELD_ID);
72 }
73
74
75 String queryTerm = request.getParameter(UifParameters.QUERY_TERM);
76 Boolean isBlankQueryTermAllowed =
77 "true".equalsIgnoreCase(request.getParameter("blankQueryTermAllowed"));
78 if ( ! isBlankQueryTermAllowed) {
79 if (StringUtils.isBlank(queryTerm)) {
80 throw new RuntimeException(
81 "Unable to find id for query term value for attribute query on under request parameter name: "
82 + UifParameters.QUERY_TERM);
83 }
84 }
85
86
87 AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService().performFieldSuggestQuery(
88 form.getPostedView(), queryFieldId, queryTerm, queryParameters);
89
90 return queryResult;
91 }
92
93 }