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