1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.web.controller; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
20 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
21 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
22 | |
import org.kuali.rice.kim.api.KimConstants; |
23 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
24 | |
import org.kuali.rice.krad.UserSession; |
25 | |
import org.kuali.rice.krad.bo.ExternalizableBusinessObject; |
26 | |
import org.kuali.rice.krad.exception.AuthorizationException; |
27 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
28 | |
import org.kuali.rice.krad.service.ModuleService; |
29 | |
import org.kuali.rice.krad.service.SessionDocumentService; |
30 | |
import org.kuali.rice.krad.uif.UifConstants; |
31 | |
import org.kuali.rice.krad.uif.UifParameters; |
32 | |
import org.kuali.rice.krad.uif.UifPropertyPaths; |
33 | |
import org.kuali.rice.krad.uif.component.Component; |
34 | |
import org.kuali.rice.krad.uif.container.CollectionGroup; |
35 | |
import org.kuali.rice.krad.uif.field.AttributeQueryResult; |
36 | |
import org.kuali.rice.krad.uif.service.ViewService; |
37 | |
import org.kuali.rice.krad.uif.util.ComponentFactory; |
38 | |
import org.kuali.rice.krad.uif.util.LookupInquiryUtils; |
39 | |
import org.kuali.rice.krad.uif.util.UifWebUtils; |
40 | |
import org.kuali.rice.krad.uif.view.History; |
41 | |
import org.kuali.rice.krad.uif.view.HistoryEntry; |
42 | |
import org.kuali.rice.krad.uif.view.View; |
43 | |
import org.kuali.rice.krad.util.GlobalVariables; |
44 | |
import org.kuali.rice.krad.util.KRADConstants; |
45 | |
import org.kuali.rice.krad.util.KRADUtils; |
46 | |
import org.kuali.rice.krad.util.UrlFactory; |
47 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
48 | |
import org.springframework.validation.BindingResult; |
49 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
50 | |
import org.springframework.web.bind.annotation.RequestMapping; |
51 | |
import org.springframework.web.bind.annotation.RequestMethod; |
52 | |
import org.springframework.web.bind.annotation.ResponseBody; |
53 | |
import org.springframework.web.servlet.ModelAndView; |
54 | |
|
55 | |
import javax.servlet.http.HttpServletRequest; |
56 | |
import javax.servlet.http.HttpServletResponse; |
57 | |
import java.util.Collections; |
58 | |
import java.util.HashMap; |
59 | |
import java.util.HashSet; |
60 | |
import java.util.List; |
61 | |
import java.util.Map; |
62 | |
import java.util.Map.Entry; |
63 | |
import java.util.Properties; |
64 | |
import java.util.Set; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 0 | public abstract class UifControllerBase { |
84 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifControllerBase.class); |
85 | |
|
86 | |
protected static final String REDIRECT_PREFIX = "redirect:"; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
@ModelAttribute(value = "KualiForm") |
96 | |
public UifFormBase initForm(HttpServletRequest request) { |
97 | 0 | UifFormBase form = null; |
98 | 0 | String formKeyParam = request.getParameter(UifParameters.FORM_KEY); |
99 | 0 | String documentNumber = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER); |
100 | |
|
101 | 0 | if (StringUtils.isNotBlank(formKeyParam)) { |
102 | 0 | form = (UifFormBase) request.getSession().getAttribute(formKeyParam); |
103 | |
|
104 | |
|
105 | 0 | if (form == null) { |
106 | 0 | UserSession userSession = (UserSession) request.getSession().getAttribute( |
107 | |
KRADConstants.USER_SESSION_KEY); |
108 | 0 | form = getSessionDocumentService().getDocumentForm(documentNumber, formKeyParam, userSession, |
109 | |
request.getRemoteAddr()); |
110 | 0 | } |
111 | |
} else { |
112 | 0 | form = createInitialForm(request); |
113 | |
} |
114 | |
|
115 | 0 | return form; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
protected abstract UifFormBase createInitialForm(HttpServletRequest request); |
126 | |
|
127 | 0 | private Set<String> methodToCallsToNotCheckAuthorization = new HashSet<String>(); |
128 | |
|
129 | |
{ |
130 | 0 | methodToCallsToNotCheckAuthorization.add("performLookup"); |
131 | 0 | methodToCallsToNotCheckAuthorization.add("performQuestion"); |
132 | 0 | methodToCallsToNotCheckAuthorization.add("performQuestionWithInput"); |
133 | 0 | methodToCallsToNotCheckAuthorization.add("performQuestionWithInputAgainBecauseOfErrors"); |
134 | 0 | methodToCallsToNotCheckAuthorization.add("performQuestionWithoutInput"); |
135 | 0 | methodToCallsToNotCheckAuthorization.add("performWorkgroupLookup"); |
136 | 0 | } |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
protected final void addMethodToCallToUncheckedList(String methodToCall) { |
144 | 0 | methodToCallsToNotCheckAuthorization.add(methodToCall); |
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public Set<String> getMethodToCallsToNotCheckAuthorization() { |
152 | 0 | return Collections.unmodifiableSet(methodToCallsToNotCheckAuthorization); |
153 | |
} |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void checkAuthorization(UifFormBase form, String methodToCall) throws AuthorizationException { |
160 | 0 | String principalId = GlobalVariables.getUserSession().getPrincipalId(); |
161 | 0 | Map<String, String> roleQualifier = new HashMap<String, String>(getRoleQualification(form, methodToCall)); |
162 | 0 | Map<String, String> permissionDetails = KRADUtils.getNamespaceAndActionClass(this.getClass()); |
163 | |
|
164 | 0 | if (!KimApiServiceLocator.getPermissionService().isAuthorizedByTemplateName(principalId, |
165 | |
KRADConstants.KRAD_NAMESPACE, KimConstants.PermissionTemplateNames.USE_SCREEN, permissionDetails, |
166 | |
roleQualifier)) { |
167 | 0 | throw new AuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), |
168 | |
methodToCall, this.getClass().getSimpleName()); |
169 | |
} |
170 | 0 | } |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
protected Map<String, String> getRoleQualification(UifFormBase form, String methodToCall) { |
177 | 0 | return new HashMap<String, String>(); |
178 | |
} |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=start") |
185 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
186 | |
HttpServletRequest request, HttpServletResponse response) { |
187 | |
|
188 | 0 | return getUIFModelAndView(form); |
189 | |
} |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine") |
197 | |
public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, |
198 | |
HttpServletRequest request, HttpServletResponse response) { |
199 | |
|
200 | 0 | String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
201 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
202 | 0 | throw new RuntimeException("Selected collection was not set for add line action, cannot add new line"); |
203 | |
} |
204 | |
|
205 | 0 | View view = uifForm.getPreviousView(); |
206 | 0 | view.getViewHelperService().processCollectionAddLine(view, uifForm, selectedCollectionPath); |
207 | |
|
208 | 0 | return updateComponent(uifForm, result, request, response); |
209 | |
} |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine") |
218 | |
public ModelAndView deleteLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, |
219 | |
HttpServletRequest request, HttpServletResponse response) { |
220 | |
|
221 | 0 | String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
222 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
223 | 0 | throw new RuntimeException("Selected collection was not set for delete line action, cannot delete line"); |
224 | |
} |
225 | |
|
226 | 0 | int selectedLineIndex = -1; |
227 | 0 | String selectedLine = uifForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
228 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
229 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
230 | |
} |
231 | |
|
232 | 0 | if (selectedLineIndex == -1) { |
233 | 0 | throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line"); |
234 | |
} |
235 | |
|
236 | 0 | View view = uifForm.getPreviousView(); |
237 | 0 | view.getViewHelperService().processCollectionDeleteLine(view, uifForm, selectedCollectionPath, |
238 | |
selectedLineIndex); |
239 | |
|
240 | 0 | return updateComponent(uifForm, result, request, response); |
241 | |
} |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=toggleInactiveRecordDisplay") |
251 | |
public ModelAndView toggleInactiveRecordDisplay(@ModelAttribute("KualiForm") UifFormBase uifForm, |
252 | |
BindingResult result, HttpServletRequest request, HttpServletResponse response) { |
253 | 0 | String collectionGroupId = request.getParameter(UifParameters.REQUESTED_COMPONENT_ID); |
254 | 0 | if (StringUtils.isBlank(collectionGroupId)) { |
255 | 0 | throw new RuntimeException( |
256 | |
"Collection group id to update for inactive record display not found in request"); |
257 | |
} |
258 | |
|
259 | 0 | String showInactiveStr = request.getParameter(UifParameters.SHOW_INACTIVE_RECORDS); |
260 | 0 | Boolean showInactive = false; |
261 | 0 | if (StringUtils.isNotBlank(showInactiveStr)) { |
262 | |
|
263 | 0 | showInactive = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(showInactiveStr); |
264 | |
} else { |
265 | 0 | throw new RuntimeException("Show inactive records flag not found in request"); |
266 | |
} |
267 | |
|
268 | 0 | CollectionGroup collectionGroup = (CollectionGroup) ComponentFactory.getNewInstanceForRefresh(uifForm.getView(), |
269 | |
collectionGroupId); |
270 | |
|
271 | |
|
272 | 0 | collectionGroup.setShowInactive(showInactive); |
273 | |
|
274 | |
|
275 | 0 | uifForm.getView().getViewHelperService().performComponentLifecycle(uifForm.getView(), uifForm, collectionGroup, |
276 | |
collectionGroupId); |
277 | |
|
278 | 0 | return UifWebUtils.getComponentModelAndView(collectionGroup, uifForm); |
279 | |
} |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
@RequestMapping(params = "methodToCall=cancel") |
285 | |
public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
286 | |
HttpServletRequest request, HttpServletResponse response) { |
287 | 0 | return close(form, result, request, response); |
288 | |
} |
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
@RequestMapping(params = "methodToCall=close") |
294 | |
public ModelAndView close(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
295 | |
HttpServletRequest request, HttpServletResponse response) { |
296 | 0 | Properties props = new Properties(); |
297 | 0 | props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH); |
298 | 0 | if (StringUtils.isNotBlank(form.getReturnFormKey())) { |
299 | 0 | props.put(UifParameters.FORM_KEY, form.getReturnFormKey()); |
300 | |
} |
301 | |
|
302 | |
|
303 | |
|
304 | 0 | String returnUrl = form.getReturnLocation(); |
305 | 0 | if (StringUtils.isBlank(returnUrl)) { |
306 | 0 | returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY); |
307 | |
} |
308 | |
|
309 | 0 | return performRedirect(form, returnUrl, props); |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
@RequestMapping(params = "methodToCall=returnToPrevious") |
318 | |
public ModelAndView returnToPrevious(@ModelAttribute("KualiForm") UifFormBase form) { |
319 | |
|
320 | 0 | return returnToHistory(form, false); |
321 | |
} |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
@RequestMapping(params = "methodToCall=returnToHub") |
329 | |
public ModelAndView returnToHub(@ModelAttribute("KualiForm") UifFormBase form) { |
330 | |
|
331 | 0 | return returnToHistory(form, true); |
332 | |
} |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
public ModelAndView returnToHistory(UifFormBase form, boolean homeFlag) { |
343 | |
|
344 | 0 | History hist = form.getFormHistory(); |
345 | 0 | List<HistoryEntry> histEntries = hist.getHistoryEntries(); |
346 | |
|
347 | |
|
348 | 0 | String histUrl = null; |
349 | 0 | if (histEntries.isEmpty()) { |
350 | 0 | histUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY); |
351 | |
} else { |
352 | |
|
353 | |
|
354 | 0 | if (homeFlag) { |
355 | 0 | histUrl = histEntries.get(0).getUrl(); |
356 | 0 | histEntries.clear(); |
357 | |
} else { |
358 | 0 | histUrl = histEntries.get(histEntries.size() - 1).getUrl(); |
359 | 0 | histEntries.remove(histEntries.size() - 1); |
360 | 0 | hist.setCurrent(null); |
361 | |
} |
362 | |
} |
363 | |
|
364 | |
|
365 | 0 | Properties props = new Properties(); |
366 | 0 | props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH); |
367 | |
|
368 | 0 | return performRedirect(form, histUrl, props); |
369 | |
} |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate") |
375 | |
public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
376 | |
HttpServletRequest request, HttpServletResponse response) { |
377 | 0 | String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID); |
378 | |
|
379 | |
|
380 | 0 | form.setRenderFullView(false); |
381 | |
|
382 | 0 | return getUIFModelAndView(form, pageId); |
383 | |
} |
384 | |
|
385 | |
@RequestMapping(params = "methodToCall=refresh") |
386 | |
public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
387 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
388 | |
|
389 | 0 | String refreshCallerType = ""; |
390 | 0 | if (request.getParameterMap().containsKey(KRADConstants.REFRESH_CALLER_TYPE)) { |
391 | 0 | refreshCallerType = request.getParameter(KRADConstants.REFRESH_CALLER_TYPE); |
392 | |
} |
393 | |
|
394 | |
|
395 | 0 | if (StringUtils.equals(refreshCallerType, UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP)) { |
396 | 0 | String lookupCollectionName = ""; |
397 | 0 | if (request.getParameterMap().containsKey(UifParameters.LOOKUP_COLLECTION_NAME)) { |
398 | 0 | lookupCollectionName = request.getParameter(UifParameters.LOOKUP_COLLECTION_NAME); |
399 | |
} |
400 | |
|
401 | 0 | if (StringUtils.isBlank(lookupCollectionName)) { |
402 | 0 | throw new RuntimeException( |
403 | |
"Lookup collection name is required for processing multi-value lookup results"); |
404 | |
} |
405 | |
|
406 | 0 | String selectedLineValues = ""; |
407 | 0 | if (request.getParameterMap().containsKey(UifParameters.SELECTED_LINE_VALUES)) { |
408 | 0 | selectedLineValues = request.getParameter(UifParameters.SELECTED_LINE_VALUES); |
409 | |
} |
410 | |
|
411 | |
|
412 | 0 | form.getPreviousView().getViewHelperService().processMultipleValueLookupResults(form.getPreviousView(), |
413 | |
form, lookupCollectionName, selectedLineValues); |
414 | |
} |
415 | |
|
416 | 0 | form.setRenderFullView(true); |
417 | |
|
418 | 0 | return getUIFModelAndView(form); |
419 | |
} |
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=updateComponent") |
428 | |
public ModelAndView updateComponent(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
429 | |
HttpServletRequest request, HttpServletResponse response) { |
430 | 0 | String requestedComponentId = request.getParameter(UifParameters.REQUESTED_COMPONENT_ID); |
431 | 0 | if (StringUtils.isBlank(requestedComponentId)) { |
432 | 0 | throw new RuntimeException("Requested component id for update not found in request"); |
433 | |
} |
434 | |
|
435 | |
|
436 | 0 | Component comp = ComponentFactory.getNewInstanceForRefresh(form.getView(), requestedComponentId); |
437 | |
|
438 | |
|
439 | 0 | form.getView().getViewHelperService().performComponentLifecycle(form.getView(), form, comp, |
440 | |
requestedComponentId); |
441 | |
|
442 | 0 | return UifWebUtils.getComponentModelAndView(comp, form); |
443 | |
} |
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=performLookup") |
450 | |
public ModelAndView performLookup(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
451 | |
HttpServletRequest request, HttpServletResponse response) { |
452 | 0 | Properties lookupParameters = form.getActionParametersAsProperties(); |
453 | |
|
454 | 0 | String lookupObjectClassName = (String) lookupParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME); |
455 | 0 | Class<?> lookupObjectClass = null; |
456 | |
try { |
457 | 0 | lookupObjectClass = Class.forName(lookupObjectClassName); |
458 | 0 | } catch (ClassNotFoundException e) { |
459 | 0 | LOG.error("Unable to get class for name: " + lookupObjectClassName); |
460 | 0 | throw new RuntimeException("Unable to get class for name: " + lookupObjectClassName, e); |
461 | 0 | } |
462 | |
|
463 | |
|
464 | 0 | String lookupParameterString = (String) lookupParameters.get(UifParameters.LOOKUP_PARAMETERS); |
465 | 0 | if (lookupParameterString != null) { |
466 | 0 | Map<String, String> lookupParameterFields = KRADUtils.getMapFromParameterString(lookupParameterString); |
467 | 0 | for (Entry<String, String> lookupParameter : lookupParameterFields.entrySet()) { |
468 | 0 | String lookupParameterValue = LookupInquiryUtils.retrieveLookupParameterValue(form, request, |
469 | |
lookupObjectClass, lookupParameter.getValue(), lookupParameter.getKey()); |
470 | |
|
471 | 0 | if (StringUtils.isNotBlank(lookupParameterValue)) { |
472 | 0 | lookupParameters.put(UifPropertyPaths.CRITERIA_FIELDS + "['" + lookupParameter.getValue() + "']", |
473 | |
lookupParameterValue); |
474 | |
} |
475 | 0 | } |
476 | |
} |
477 | |
|
478 | |
|
479 | |
|
480 | 0 | String baseLookupUrl = (String) lookupParameters.get(UifParameters.BASE_LOOKUP_URL); |
481 | 0 | lookupParameters.remove(UifParameters.BASE_LOOKUP_URL); |
482 | |
|
483 | |
|
484 | 0 | lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START); |
485 | 0 | String autoSearchString = (String) lookupParameters.get(UifParameters.AUTO_SEARCH); |
486 | 0 | if (Boolean.parseBoolean(autoSearchString)) { |
487 | 0 | lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.SEARCH); |
488 | |
} |
489 | |
|
490 | 0 | lookupParameters.put(UifParameters.RETURN_LOCATION, form.getFormPostUrl()); |
491 | 0 | lookupParameters.put(UifParameters.RETURN_FORM_KEY, form.getFormKey()); |
492 | |
|
493 | |
|
494 | 0 | if (lookupObjectClass != null) { |
495 | 0 | ModuleService responsibleModuleService = |
496 | |
KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(lookupObjectClass); |
497 | 0 | if (responsibleModuleService != null && responsibleModuleService.isExternalizable(lookupObjectClass)) { |
498 | 0 | Class<? extends ExternalizableBusinessObject> implLookupObjectClass = |
499 | |
responsibleModuleService.getExternalizableBusinessObjectImplementation( |
500 | |
lookupObjectClass.asSubclass(ExternalizableBusinessObject.class)); |
501 | |
|
502 | 0 | if (implLookupObjectClass != null) { |
503 | 0 | lookupParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, implLookupObjectClass.getName()); |
504 | |
} else { |
505 | 0 | throw new RuntimeException( |
506 | |
"Unable to find implementation class for EBO: " + lookupObjectClass.getName()); |
507 | |
} |
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
} |
521 | |
} |
522 | |
|
523 | 0 | return performRedirect(form, baseLookupUrl, lookupParameters); |
524 | |
} |
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest") |
533 | |
public |
534 | |
@ResponseBody |
535 | |
AttributeQueryResult performFieldSuggest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
536 | |
HttpServletRequest request, HttpServletResponse response) { |
537 | |
|
538 | |
|
539 | 0 | Map<String, String> queryParameters = new HashMap<String, String>(); |
540 | 0 | for (Object parameterName : request.getParameterMap().keySet()) { |
541 | 0 | if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) { |
542 | 0 | String fieldName = StringUtils.substringAfter(parameterName.toString(), |
543 | |
UifParameters.QUERY_PARAMETER + "."); |
544 | 0 | String fieldValue = request.getParameter(parameterName.toString()); |
545 | 0 | queryParameters.put(fieldName, fieldValue); |
546 | 0 | } |
547 | |
} |
548 | |
|
549 | |
|
550 | 0 | String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID); |
551 | 0 | if (StringUtils.isBlank(queryFieldId)) { |
552 | 0 | throw new RuntimeException("Unable to find id for field to perform query on under request parameter name: " |
553 | |
+ UifParameters.QUERY_FIELD_ID); |
554 | |
} |
555 | |
|
556 | |
|
557 | 0 | String queryTerm = request.getParameter(UifParameters.QUERY_TERM); |
558 | 0 | if (StringUtils.isBlank(queryTerm)) { |
559 | 0 | throw new RuntimeException( |
560 | |
"Unable to find id for query term value for attribute query on under request parameter name: " |
561 | |
+ UifParameters.QUERY_TERM); |
562 | |
} |
563 | |
|
564 | |
|
565 | 0 | AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService().performFieldSuggestQuery( |
566 | |
form.getView(), queryFieldId, queryTerm, queryParameters); |
567 | |
|
568 | 0 | return queryResult; |
569 | |
} |
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
@RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldQuery") |
579 | |
public |
580 | |
@ResponseBody |
581 | |
AttributeQueryResult performFieldQuery(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
582 | |
HttpServletRequest request, HttpServletResponse response) { |
583 | |
|
584 | |
|
585 | 0 | Map<String, String> queryParameters = new HashMap<String, String>(); |
586 | 0 | for (Object parameterName : request.getParameterMap().keySet()) { |
587 | 0 | if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) { |
588 | 0 | String fieldName = StringUtils.substringAfter(parameterName.toString(), |
589 | |
UifParameters.QUERY_PARAMETER + "."); |
590 | 0 | String fieldValue = request.getParameter(parameterName.toString()); |
591 | 0 | queryParameters.put(fieldName, fieldValue); |
592 | 0 | } |
593 | |
} |
594 | |
|
595 | |
|
596 | 0 | String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID); |
597 | 0 | if (StringUtils.isBlank(queryFieldId)) { |
598 | 0 | throw new RuntimeException("Unable to find id for field to perform query on under request parameter name: " |
599 | |
+ UifParameters.QUERY_FIELD_ID); |
600 | |
} |
601 | |
|
602 | |
|
603 | 0 | AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService().performFieldQuery( |
604 | |
form.getView(), queryFieldId, queryParameters); |
605 | |
|
606 | 0 | return queryResult; |
607 | |
} |
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) { |
619 | |
|
620 | 0 | form.setView(form.getPreviousView()); |
621 | |
|
622 | |
|
623 | 0 | urlParameters.setProperty(UifConstants.UrlParams.HISTORY, form.getFormHistory().getHistoryParameterString()); |
624 | |
|
625 | |
|
626 | |
|
627 | 0 | if (urlParameters.get(UifParameters.LIGHTBOX_CALL) != null && |
628 | |
urlParameters.get(UifParameters.LIGHTBOX_CALL).equals("true")) { |
629 | 0 | urlParameters.remove(UifParameters.LIGHTBOX_CALL); |
630 | 0 | String redirectUrl = UrlFactory.parameterizeUrl(baseUrl, urlParameters); |
631 | |
|
632 | 0 | ModelAndView modelAndView = new ModelAndView(UifConstants.SPRING_REDIRECT_ID); |
633 | 0 | modelAndView.addObject("redirectUrl", redirectUrl); |
634 | 0 | return modelAndView; |
635 | |
} |
636 | |
|
637 | 0 | String redirectUrl = UrlFactory.parameterizeUrl(baseUrl, urlParameters); |
638 | 0 | ModelAndView modelAndView = new ModelAndView(REDIRECT_PREFIX + redirectUrl); |
639 | |
|
640 | 0 | return modelAndView; |
641 | |
} |
642 | |
|
643 | |
protected ModelAndView getUIFModelAndView(UifFormBase form) { |
644 | 0 | return getUIFModelAndView(form, form.getPageId()); |
645 | |
} |
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
protected ModelAndView getUIFModelAndView(UifFormBase form, String pageId) { |
657 | 0 | return UifWebUtils.getUIFModelAndView(form, pageId); |
658 | |
} |
659 | |
|
660 | |
protected ViewService getViewService() { |
661 | 0 | return KRADServiceLocatorWeb.getViewService(); |
662 | |
} |
663 | |
|
664 | |
public SessionDocumentService getSessionDocumentService() { |
665 | 0 | return KRADServiceLocatorWeb.getSessionDocumentService(); |
666 | |
} |
667 | |
|
668 | |
} |