1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.preferences.web; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.servlet.http.HttpServletRequest; |
23 | |
import javax.servlet.http.HttpServletResponse; |
24 | |
|
25 | |
import org.apache.commons.lang.StringUtils; |
26 | |
import org.apache.struts.action.ActionForm; |
27 | |
import org.apache.struts.action.ActionForward; |
28 | |
import org.apache.struts.action.ActionMapping; |
29 | |
import org.apache.struts.action.ActionMessages; |
30 | |
import org.kuali.rice.core.config.ConfigContext; |
31 | |
import org.kuali.rice.core.util.JSTLConstants; |
32 | |
import org.kuali.rice.kew.preferences.Preferences; |
33 | |
import org.kuali.rice.kew.preferences.service.PreferencesService; |
34 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
35 | |
import org.kuali.rice.kew.util.KEWConstants; |
36 | |
import org.kuali.rice.kew.web.KewKualiAction; |
37 | |
import org.kuali.rice.kew.web.KeyValue; |
38 | |
import org.kuali.rice.kew.web.session.UserSession; |
39 | |
import org.kuali.rice.kns.util.GlobalVariables; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class PreferencesAction extends KewKualiAction { |
51 | |
|
52 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
53 | 0 | initForm(request, form); |
54 | 0 | request.setAttribute("Constants", new JSTLConstants(KEWConstants.class)); |
55 | 0 | return super.execute(mapping, form, request, response); |
56 | |
} |
57 | |
|
58 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
59 | 0 | PreferencesService preferencesService = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE); |
60 | 0 | PreferencesForm preferencesForm = (PreferencesForm) form; |
61 | 0 | preferencesForm.setPreferences(preferencesService.getPreferences(getUserSession(request).getPrincipalId())); |
62 | 0 | return mapping.findForward("basic"); |
63 | |
} |
64 | |
|
65 | |
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
66 | 0 | PreferencesService prefSrv = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE); |
67 | 0 | PreferencesForm prefForm = (PreferencesForm) form; |
68 | |
|
69 | 0 | prefForm.validatePreferences(); |
70 | 0 | if (GlobalVariables.getMessageMap().hasNoErrors()) { |
71 | 0 | prefSrv.savePreferences(getUserSession(request).getPrincipalId(), prefForm.getPreferences()); |
72 | |
} |
73 | 0 | getUserSession(request).refreshPreferences(); |
74 | 0 | if (! StringUtils.isEmpty(prefForm.getReturnMapping())) { |
75 | 0 | return mapping.findForward(prefForm.getReturnMapping()); |
76 | |
} |
77 | 0 | return mapping.findForward("basic"); |
78 | |
} |
79 | |
|
80 | |
public ActionMessages initForm(HttpServletRequest request, ActionForm form) throws Exception { |
81 | 0 | request.setAttribute("actionListContent", KEWConstants.ACTION_LIST_CONTENT); |
82 | 0 | getDelegatorFilterChoices(request); |
83 | 0 | getPrimaryDelegateFilterChoices(request); |
84 | 0 | PreferencesForm prefForm = (PreferencesForm)form; |
85 | 0 | prefForm.setShowOutbox(ConfigContext.getCurrentContextConfig().getOutBoxOn()); |
86 | 0 | return null; |
87 | |
} |
88 | |
|
89 | |
public void getDelegatorFilterChoices(HttpServletRequest request) { |
90 | 0 | List delegatorFilterChoices = new ArrayList(); |
91 | 0 | delegatorFilterChoices.add(new KeyValue(KEWConstants.DELEGATORS_ON_FILTER_PAGE, KEWConstants.DELEGATORS_ON_FILTER_PAGE)); |
92 | 0 | delegatorFilterChoices.add(new KeyValue(KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE, KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE)); |
93 | 0 | request.setAttribute("delegatorFilter", delegatorFilterChoices); |
94 | 0 | } |
95 | |
|
96 | |
public void getPrimaryDelegateFilterChoices(HttpServletRequest request) { |
97 | 0 | List<KeyValue> primaryDelegateFilterChoices = new ArrayList<KeyValue>(); |
98 | 0 | primaryDelegateFilterChoices.add(new KeyValue(KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE)); |
99 | 0 | primaryDelegateFilterChoices.add(new KeyValue(KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE)); |
100 | 0 | request.setAttribute("primaryDelegateFilter", primaryDelegateFilterChoices); |
101 | 0 | } |
102 | |
|
103 | |
private static UserSession getUserSession(HttpServletRequest request) { |
104 | 0 | return UserSession.getAuthenticatedUser(); |
105 | |
} |
106 | |
} |