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.api.util.ConcreteKeyValue;
26 import org.kuali.rice.core.api.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 public class PreferencesAction extends KewKualiAction {
50
51 @Override
52 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
53 initForm(request, form);
54 request.setAttribute("Constants", getServlet().getServletContext().getAttribute("KEWConstants"));
55 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 PreferencesService preferencesService = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE);
61 PreferencesForm preferencesForm = (PreferencesForm) form;
62 preferencesForm.setPreferences(preferencesService.getPreferences(getUserSession().getPrincipalId()));
63 return mapping.findForward("basic");
64 }
65
66 public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
67 PreferencesService prefSrv = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE);
68 PreferencesForm prefForm = (PreferencesForm) form;
69
70 prefForm.validatePreferences();
71 if (GlobalVariables.getMessageMap().hasNoErrors()) {
72 prefSrv.savePreferences(getUserSession().getPrincipalId(), prefForm.getPreferences());
73 }
74
75 GlobalVariables.getUserSession().addObject(KEWConstants.UPDATE_ACTION_LIST_ATTR_NAME, Boolean.TRUE);
76 GlobalVariables.getUserSession().removeObject(KEWConstants.PREFERENCES);
77
78 if (! StringUtils.isEmpty(prefForm.getReturnMapping())) {
79 return mapping.findForward(prefForm.getReturnMapping());
80 }
81 return mapping.findForward("basic");
82 }
83
84 public ActionMessages initForm(HttpServletRequest request, ActionForm form) throws Exception {
85 request.setAttribute("actionListContent", KEWConstants.ACTION_LIST_CONTENT);
86 getDelegatorFilterChoices(request);
87 getPrimaryDelegateFilterChoices(request);
88 PreferencesForm prefForm = (PreferencesForm)form;
89 prefForm.setShowOutbox(ConfigContext.getCurrentContextConfig().getOutBoxOn());
90 return null;
91 }
92
93 public void getDelegatorFilterChoices(HttpServletRequest request) {
94 List<KeyValue> delegatorFilterChoices = new ArrayList<KeyValue>();
95 delegatorFilterChoices.add(new ConcreteKeyValue(KEWConstants.DELEGATORS_ON_FILTER_PAGE, KEWConstants.DELEGATORS_ON_FILTER_PAGE));
96 delegatorFilterChoices.add(new ConcreteKeyValue(KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE, KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE));
97 request.setAttribute("delegatorFilter", delegatorFilterChoices);
98 }
99
100 public void getPrimaryDelegateFilterChoices(HttpServletRequest request) {
101 List<KeyValue> primaryDelegateFilterChoices = new ArrayList<KeyValue>();
102 primaryDelegateFilterChoices.add(new ConcreteKeyValue(KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE));
103 primaryDelegateFilterChoices.add(new ConcreteKeyValue(KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE));
104 request.setAttribute("primaryDelegateFilter", primaryDelegateFilterChoices);
105 }
106
107 private static UserSession getUserSession() {
108 return GlobalVariables.getUserSession();
109 }
110 }