1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.preferences.web;
17
18 import javax.servlet.http.HttpServletRequest;
19
20 import org.kuali.rice.kew.api.preferences.Preferences;
21 import org.kuali.rice.kns.web.struts.form.KualiForm;
22 import org.kuali.rice.krad.exception.ValidationException;
23 import org.kuali.rice.krad.util.GlobalVariables;
24 import org.kuali.rice.krad.util.KRADConstants;
25
26
27
28
29
30
31
32
33
34 public class PreferencesForm extends KualiForm {
35
36 private static final long serialVersionUID = 4536869031291955777L;
37 private static final String ERR_KEY_REFRESH_RATE_WHOLE_NUM = "preferences.refreshRate";
38 private static final String ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM = "preferences.pageSize";
39 private Preferences.Builder preferences;
40 private String methodToCall = "";
41 private String returnMapping;
42 private boolean showOutbox = true;
43
44
45 private String backLocation;
46
47 public String getReturnMapping() {
48 return returnMapping;
49 }
50 public void setReturnMapping(String returnMapping) {
51 this.returnMapping = returnMapping;
52 }
53 public PreferencesForm() {
54 preferences = Preferences.Builder.create();
55 }
56 public String getMethodToCall() {
57 return methodToCall;
58 }
59 public void setMethodToCall(String methodToCall) {
60 this.methodToCall = methodToCall;
61 }
62 public Preferences.Builder getPreferences() {
63 return preferences;
64 }
65 public void setPreferences(Preferences.Builder preferences) {
66 this.preferences = preferences;
67 }
68 public boolean isShowOutbox() {
69 return this.showOutbox;
70 }
71 public void setShowOutbox(boolean showOutbox) {
72 this.showOutbox = showOutbox;
73 }
74
75 public String getBackLocation() {
76 return this.backLocation;
77 }
78 public void setBackLocation(String backLocation) {
79 this.backLocation = backLocation;
80 }
81
82
83
84
85
86
87 @Override
88 public void populate(HttpServletRequest request) {
89 super.populate(request);
90
91 if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
92 setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER));
93 }
94 }
95
96 public void validatePreferences() {
97
98 try {
99 new Integer(preferences.getRefreshRate().trim());
100 } catch (NumberFormatException e) {
101 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
102 } catch (NullPointerException e1) {
103 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
104 }
105
106 try {
107 if(new Integer(preferences.getPageSize().trim()) == 0){
108 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be non-zero ");
109 }
110 } catch (NumberFormatException e) {
111 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
112 } catch (NullPointerException e1) {
113 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
114 }
115
116 if (GlobalVariables.getMessageMap().hasErrors()) {
117 throw new ValidationException("errors in preferences");
118 }
119 }
120 }