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 private String documentTypePreferenceName;
44 private String documentTypePreferenceValue;
45
46
47 private String backLocation;
48
49 public String getReturnMapping() {
50 return returnMapping;
51 }
52 public void setReturnMapping(String returnMapping) {
53 this.returnMapping = returnMapping;
54 }
55 public PreferencesForm() {
56 preferences = Preferences.Builder.create();
57 }
58 public String getMethodToCall() {
59 return methodToCall;
60 }
61 public void setMethodToCall(String methodToCall) {
62 this.methodToCall = methodToCall;
63 }
64 public Preferences.Builder getPreferences() {
65 return preferences;
66 }
67 public void setPreferences(Preferences.Builder preferences) {
68 this.preferences = preferences;
69 }
70 public boolean isShowOutbox() {
71 return this.showOutbox;
72 }
73 public void setShowOutbox(boolean showOutbox) {
74 this.showOutbox = showOutbox;
75 }
76
77 public String getBackLocation() {
78 return this.backLocation;
79 }
80 public void setBackLocation(String backLocation) {
81 this.backLocation = backLocation;
82 }
83
84 public String getDocumentTypePreferenceName() {
85 return documentTypePreferenceName;
86 }
87
88 public void setDocumentTypePreferenceName(String documentTypePreferenceName) {
89 this.documentTypePreferenceName = documentTypePreferenceName;
90 }
91
92 public String getDocumentTypePreferenceValue() {
93 return documentTypePreferenceValue;
94 }
95
96 public void setDocumentTypePreferenceValue(String documentTypePreferenceValue) {
97 this.documentTypePreferenceValue = documentTypePreferenceValue;
98 }
99
100 public Object getDocumentTypeNotificationPreference(String documentType) {
101 return preferences.getDocumentTypeNotificationPreference(documentType);
102 }
103
104 public void setDocumentTypeNotificationPreference(String documentType, String preferenceValue) {
105 preferences.addDocumentTypeNotificationPreference(documentType, preferenceValue);
106 }
107
108
109
110
111
112
113 @Override
114 public void populate(HttpServletRequest request) {
115 super.populate(request);
116
117 if (getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER) != null) {
118 setBackLocation(getParameter(request, KRADConstants.RETURN_LOCATION_PARAMETER));
119 }
120 }
121
122 public void validatePreferences() {
123
124 try {
125 new Integer(preferences.getRefreshRate().trim());
126 } catch (NumberFormatException e) {
127 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
128 } catch (NullPointerException e1) {
129 GlobalVariables.getMessageMap().putError(ERR_KEY_REFRESH_RATE_WHOLE_NUM, "general.message", "ActionList Refresh Rate must be in whole minutes");
130 }
131
132 try {
133 if(new Integer(preferences.getPageSize().trim()) == 0){
134 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be non-zero ");
135 }
136 } catch (NumberFormatException e) {
137 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
138 } catch (NullPointerException e1) {
139 GlobalVariables.getMessageMap().putError(ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM, "general.message", "ActionList Page Size must be in whole minutes");
140 }
141
142 if (GlobalVariables.getMessageMap().hasErrors()) {
143 throw new ValidationException("errors in preferences");
144 }
145 }
146 }