1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.check.controller;
17
18 import org.apache.commons.lang.BooleanUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
24 import org.kuali.rice.krad.util.KRADConstants;
25 import org.kuali.rice.krad.web.controller.LookupController;
26 import org.kuali.rice.krad.web.form.LookupForm;
27 import org.kuali.student.enrollment.uif.view.KSLookupView;
28 import org.springframework.stereotype.Controller;
29 import org.springframework.validation.BindingResult;
30 import org.springframework.web.bind.annotation.ModelAttribute;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.servlet.ModelAndView;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36 import java.util.List;
37 import java.util.Properties;
38
39
40
41
42
43
44 @Controller
45 @RequestMapping(value = "/checkLookup")
46 public class CheckInfolookupController extends LookupController {
47
48 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CheckInfolookupController.class);
49
50
51
52
53 @RequestMapping(params = "methodToCall=search")
54 public ModelAndView search(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result,
55 HttpServletRequest request, HttpServletResponse response) {
56 lookupForm.setRenderedInLightBox(true);
57 ModelAndView modelAndView = super.search(lookupForm,result,request,response);
58
59 if(lookupForm.getPostedView() instanceof KSLookupView){
60 KSLookupView ksLookupView = (KSLookupView)lookupForm.getPostedView();
61 String defaultAction = ksLookupView.getDefaultSingleLookupResultAction();
62 if (StringUtils.isNotBlank(defaultAction) && lookupForm.getLookupResults() != null && lookupForm.getLookupResults().size() == 1){
63 Object object = lookupForm.getLookupResults().iterator().next();
64
65 Properties props = new Properties();
66
67 DataObjectEntry ddEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(lookupForm.getDataObjectClassName());
68
69 List<String> pkKeys = ddEntry.getPrimaryKeys();
70 for (String pkKey : pkKeys) {
71 props.put(pkKey,ObjectPropertyUtils.getPropertyValue(object, pkKey));
72 }
73
74 if(StringUtils.equals(defaultAction,KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_MAINTENANCE)){
75 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.Maintenance.METHOD_TO_CALL_EDIT);
76 } else{
77 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, UifConstants.MethodToCallNames.START);
78 }
79 props.put(UifConstants.UrlParams.SHOW_HISTORY, BooleanUtils.toStringTrueFalse(false));
80 props.put(UifConstants.UrlParams.SHOW_HOME,BooleanUtils.toStringTrueFalse(false));
81 props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE,lookupForm.getDataObjectClassName());
82
83 return performRedirect(lookupForm,defaultAction,props );
84 }
85 }
86
87 return modelAndView;
88 }
89
90 }