1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.spring.controller; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
import java.util.List; |
20 | |
import java.util.Properties; |
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.kim.bo.Person; |
27 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
28 | |
import org.kuali.rice.kim.util.KimConstants; |
29 | |
import org.kuali.rice.kns.exception.AuthorizationException; |
30 | |
import org.kuali.rice.kns.lookup.CollectionIncomplete; |
31 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
32 | |
import org.kuali.rice.kns.uif.UifConstants; |
33 | |
import org.kuali.rice.kns.uif.UifParameters; |
34 | |
import org.kuali.rice.kns.uif.container.LookupView; |
35 | |
import org.kuali.rice.kns.uif.core.Component; |
36 | |
import org.kuali.rice.kns.uif.service.LookupViewHelperService; |
37 | |
import org.kuali.rice.kns.util.GlobalVariables; |
38 | |
import org.kuali.rice.kns.util.KNSConstants; |
39 | |
import org.kuali.rice.kns.util.KNSUtils; |
40 | |
import org.kuali.rice.kns.web.spring.form.LookupForm; |
41 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
42 | |
import org.springframework.stereotype.Controller; |
43 | |
import org.springframework.validation.BindingResult; |
44 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
45 | |
import org.springframework.web.bind.annotation.RequestMapping; |
46 | |
import org.springframework.web.servlet.ModelAndView; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | @Controller |
54 | |
@RequestMapping(value = "/lookup") |
55 | 0 | public class LookupController extends UifControllerBase { |
56 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupController.class); |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
protected LookupForm createInitialForm(HttpServletRequest request) { |
63 | 0 | return new LookupForm(); |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Override |
70 | |
public void checkAuthorization(UifFormBase form, String methodToCall) throws AuthorizationException { |
71 | 0 | if (!(form instanceof LookupForm)) { |
72 | 0 | super.checkAuthorization(form, methodToCall); |
73 | |
} else { |
74 | 0 | LookupForm lookupForm = (LookupForm) form; |
75 | |
try { |
76 | 0 | Class<?> dataObjectClass = Class.forName(lookupForm.getDataObjectClassName()); |
77 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
78 | |
|
79 | 0 | String documentTypeName = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService().getDocumentTypeName(dataObjectClass); |
80 | 0 | if ((documentTypeName != null) && !KNSServiceLocatorWeb.getDocumentHelperService().getDocumentAuthorizer(documentTypeName).canInitiate(documentTypeName, user)) { |
81 | 0 | lookupForm.setSuppressActions( true ); |
82 | |
} |
83 | |
|
84 | 0 | if (!KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName(user.getPrincipalId(), KNSConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.LOOK_UP_RECORDS, KNSUtils.getNamespaceAndComponentSimpleName(dataObjectClass), null)) { |
85 | 0 | throw new AuthorizationException(user.getPrincipalName(), |
86 | |
KimConstants.PermissionTemplateNames.LOOK_UP_RECORDS, |
87 | |
dataObjectClass.getSimpleName()); |
88 | |
} |
89 | |
} |
90 | 0 | catch (ClassNotFoundException e) { |
91 | 0 | LOG.warn("Unable to load BusinessObject class: " + lookupForm.getDataObjectClassName(), e); |
92 | 0 | super.checkAuthorization(lookupForm, methodToCall); |
93 | 0 | } |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
@RequestMapping(params = "methodToCall=start") |
98 | |
public ModelAndView start(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result, HttpServletRequest request, HttpServletResponse response) { |
99 | |
|
100 | 0 | return getUIFModelAndView(lookupForm); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
@Override |
107 | |
@RequestMapping(params = "methodToCall=cancel") |
108 | |
public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) { |
109 | 0 | LookupForm lookupForm = (LookupForm)form; |
110 | |
|
111 | 0 | Properties props = new Properties(); |
112 | 0 | props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH); |
113 | 0 | if (StringUtils.isNotBlank(lookupForm.getReturnFormKey())) { |
114 | 0 | props.put(UifParameters.FORM_KEY, lookupForm.getReturnFormKey()); |
115 | |
} |
116 | 0 | if (StringUtils.isNotBlank(lookupForm.getDocNum())) { |
117 | 0 | props.put(UifParameters.DOC_NUM, lookupForm.getDocNum()); |
118 | |
} |
119 | 0 | return performRedirect(lookupForm, lookupForm.getReturnLocation(), props); |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
@RequestMapping(params = "methodToCall=clearValues") |
126 | |
public ModelAndView clearValues(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result, HttpServletRequest request, HttpServletResponse response) { |
127 | |
|
128 | 0 | LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) lookupForm.getView().getViewHelperService(); |
129 | 0 | lookupForm.setCriteriaFields(lookupViewHelperService.performClear(lookupForm.getCriteriaFieldsForLookup())); |
130 | 0 | return getUIFModelAndView(lookupForm); |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
@RequestMapping(params = "methodToCall=search") |
137 | |
public ModelAndView search(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result, HttpServletRequest request, HttpServletResponse response) { |
138 | 0 | GlobalVariables.getUserSession().removeObjectsByPrefix(KNSConstants.SEARCH_METHOD); |
139 | |
|
140 | |
|
141 | 0 | LookupViewHelperService lookupViewHelperService = (LookupViewHelperService) lookupForm.getView().getViewHelperService(); |
142 | 0 | if (lookupViewHelperService == null) { |
143 | 0 | LOG.error("LookupViewHelperService is null."); |
144 | 0 | throw new RuntimeException("LookupViewHelperService is null."); |
145 | |
} |
146 | |
|
147 | |
|
148 | 0 | List<? extends Component> criteriaComponents = ((LookupView) lookupForm.getView()).getCriteriaGroup().getItems(); |
149 | 0 | lookupViewHelperService.validateSearchParameters(criteriaComponents, lookupForm.getCriteriaFields()); |
150 | |
|
151 | 0 | Collection<?> displayList = lookupViewHelperService.performSearch(lookupForm.getCriteriaFieldsForLookup(), true); |
152 | |
|
153 | 0 | if ( displayList instanceof CollectionIncomplete<?> ){ |
154 | 0 | request.setAttribute("reqSearchResultsActualSize", ((CollectionIncomplete<?>) displayList).getActualSizeIfTruncated()); |
155 | |
} else { |
156 | 0 | request.setAttribute("reqSearchResultsActualSize", new Integer(displayList.size()) ); |
157 | |
} |
158 | |
|
159 | 0 | lookupForm.setSearchResults(displayList); |
160 | |
|
161 | 0 | return getUIFModelAndView(lookupForm); |
162 | |
} |
163 | |
|
164 | |
} |