1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.preferences.service.impl; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
19 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
20 | |
import org.kuali.rice.kew.api.preferences.Preferences; |
21 | |
import org.kuali.rice.kew.api.preferences.PreferencesService; |
22 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
23 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
24 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
25 | |
import org.kuali.rice.kew.useroptions.UserOptions; |
26 | |
import org.kuali.rice.kew.useroptions.UserOptionsService; |
27 | |
import org.kuali.rice.kew.api.KewApiConstants; |
28 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
29 | |
|
30 | |
import java.util.ArrayList; |
31 | |
import java.util.Collection; |
32 | |
import java.util.HashMap; |
33 | |
import java.util.Map; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class PreferencesServiceImpl implements PreferencesService { |
42 | |
|
43 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PreferencesServiceImpl.class); |
44 | |
|
45 | |
private static Map<String, String> USER_OPTION_KEY_DEFAULT_MAP; |
46 | |
|
47 | |
static { |
48 | 0 | USER_OPTION_KEY_DEFAULT_MAP = new HashMap<String, String>(); |
49 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_APPROVED, "userOptions.default.color"); |
50 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_CANCELED, "userOptions.default.color"); |
51 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_DISAPPROVE_CANCEL, "userOptions.default.color"); |
52 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_DISAPPROVED, "userOptions.default.color"); |
53 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_ENROUTE, "userOptions.default.color"); |
54 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_EXCEPTION, "userOptions.default.color"); |
55 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_FINAL, "userOptions.default.color"); |
56 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_INITIATED, "userOptions.default.color"); |
57 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_PROCESSED, "userOptions.default.color"); |
58 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.COLOR_SAVED, "userOptions.default.color"); |
59 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.EMAIL_NOTIFICATION, "userOptions.default.email"); |
60 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_PRIMARY_DELEGATION, "userOptions.default.notifyPrimary"); |
61 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_SECONDARY_DELEGATION, "userOptions.default.notifySecondary"); |
62 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.OPEN_NEW_WINDOW, "userOptions.default.openNewWindow"); |
63 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.PAGE_SIZE, "userOptions.default.actionListSize"); |
64 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.REFRESH_RATE, "userOptions.default.refreshRate"); |
65 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_ACTION_REQUESTED, "userOptions.default.showActionRequired"); |
66 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DATE_CREATED, "userOptions.default.showDateCreated"); |
67 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DOC_TYPE, "userOptions.default.showDocumentType"); |
68 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DOCUMENT_STATUS, "userOptions.default.showDocumentStatus"); |
69 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_INITIATOR, "showInitiator"); |
70 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DELEGATOR, "userOptions.default.showDelegator"); |
71 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DOC_TITLE, "userOptions.default.showTitle"); |
72 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_GROUP_REQUEST, "userOptions.default.showWorkgroupRequest"); |
73 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_CLEAR_FYI, "userOptions.default.showClearFYI"); |
74 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.DELEGATOR_FILTER, "userOptions.default.delegatorFilterOnActionList"); |
75 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.PRIMARY_DELEGATE_FILTER, "userOptions.default.primaryDelegatorFilterOnActionList"); |
76 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_DATE_APPROVED, "userOptions.default.showLastApprovedDate"); |
77 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.SHOW_CURRENT_NODE, "userOptions.default.showCurrentNode"); |
78 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.USE_OUT_BOX, KewApiConstants.USER_OPTIONS_DEFAULT_USE_OUTBOX_PARAM); |
79 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_ACKNOWLEDGE, "userOptions.default.notifyAcknowledge"); |
80 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_APPROVE, "userOptions.default.notifyApprove"); |
81 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_COMPLETE, "userOptions.default.notifyComplete"); |
82 | 0 | USER_OPTION_KEY_DEFAULT_MAP.put(Preferences.KEYS.NOTIFY_FYI, "userOptions.default.notifyFYI"); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
public Preferences getPreferences(String principalId) { |
87 | 0 | if ( LOG.isDebugEnabled() ) { |
88 | 0 | LOG.debug("start preferences fetch user " + principalId); |
89 | |
} |
90 | 0 | Collection<UserOptions> options = getUserOptionService().findByWorkflowUser(principalId); |
91 | 0 | Map<String,UserOptions> optionMap = new HashMap<String, UserOptions>(); |
92 | 0 | Map<String,String> optionValueMap = new HashMap<String, String>(); |
93 | 0 | for ( UserOptions option : options ) { |
94 | 0 | optionMap.put(option.getOptionId(), option); |
95 | |
} |
96 | |
|
97 | 0 | ConfigurationService kcs = KRADServiceLocator.getKualiConfigurationService(); |
98 | |
|
99 | 0 | boolean isSaveRequired = false; |
100 | |
|
101 | 0 | for (Map.Entry<String, String> entry : USER_OPTION_KEY_DEFAULT_MAP.entrySet()) { |
102 | 0 | String optionKey = entry.getKey(); |
103 | 0 | String defaultValue = kcs.getPropertyValueAsString(entry.getValue()); |
104 | 0 | if (LOG.isDebugEnabled()) { |
105 | 0 | LOG.debug("start fetch option " + optionKey + " user " + principalId); |
106 | |
} |
107 | |
|
108 | 0 | UserOptions option = optionMap.get(optionKey); |
109 | 0 | if (option == null) { |
110 | 0 | if (LOG.isDebugEnabled()) { |
111 | 0 | LOG.debug("User option '" |
112 | |
+ optionKey |
113 | |
+ "' on user " |
114 | |
+ principalId |
115 | |
+ " has no stored value. Preferences will require save."); |
116 | |
} |
117 | 0 | option = new UserOptions(); |
118 | 0 | option.setWorkflowId(principalId); |
119 | 0 | option.setOptionId(optionKey); |
120 | 0 | option.setOptionVal(defaultValue); |
121 | 0 | optionMap.put(optionKey, option); |
122 | |
|
123 | 0 | if (!isSaveRequired) { |
124 | 0 | if (optionKey.equals(Preferences.KEYS.USE_OUT_BOX) && !ConfigContext.getCurrentContextConfig().getOutBoxOn()) { |
125 | |
|
126 | |
} else { |
127 | 0 | isSaveRequired = true; |
128 | |
} |
129 | |
} |
130 | |
} |
131 | 0 | if (LOG.isDebugEnabled()) { |
132 | 0 | LOG.debug("End fetch option " + optionKey + " user " + principalId); |
133 | |
} |
134 | |
|
135 | 0 | optionValueMap.put(optionKey, option.getOptionVal()); |
136 | 0 | } |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 0 | return Preferences.Builder.create(optionValueMap, isSaveRequired).build(); |
143 | |
} |
144 | |
|
145 | |
public void savePreferences(String principalId, Preferences preferences) { |
146 | |
|
147 | 0 | if ( LOG.isDebugEnabled() ) { |
148 | 0 | LOG.debug("saving preferences user " + principalId); |
149 | |
} |
150 | |
|
151 | 0 | validate(preferences); |
152 | 0 | Map<String,String> optionsMap = new HashMap<String,String>(50); |
153 | |
|
154 | 0 | optionsMap.put(Preferences.KEYS.COLOR_DISAPPROVE_CANCEL, preferences.getColorDisapproveCancel()); |
155 | 0 | optionsMap.put(Preferences.KEYS.COLOR_DISAPPROVED, preferences.getColorDisapproved()); |
156 | 0 | optionsMap.put(Preferences.KEYS.COLOR_APPROVED, preferences.getColorApproved()); |
157 | 0 | optionsMap.put(Preferences.KEYS.COLOR_CANCELED, preferences.getColorCanceled()); |
158 | 0 | optionsMap.put(Preferences.KEYS.COLOR_SAVED, preferences.getColorSaved()); |
159 | 0 | optionsMap.put(Preferences.KEYS.COLOR_ENROUTE, preferences.getColorEnroute()); |
160 | 0 | optionsMap.put(Preferences.KEYS.COLOR_PROCESSED, preferences.getColorProcessed()); |
161 | 0 | optionsMap.put(Preferences.KEYS.COLOR_INITIATED, preferences.getColorInitiated()); |
162 | 0 | optionsMap.put(Preferences.KEYS.COLOR_FINAL, preferences.getColorFinal()); |
163 | 0 | optionsMap.put(Preferences.KEYS.COLOR_EXCEPTION, preferences.getColorException()); |
164 | 0 | optionsMap.put(Preferences.KEYS.REFRESH_RATE, preferences.getRefreshRate().trim()); |
165 | 0 | optionsMap.put(Preferences.KEYS.OPEN_NEW_WINDOW, preferences.getOpenNewWindow()); |
166 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DOC_TYPE, preferences.getShowDocType()); |
167 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DOC_TITLE, preferences.getShowDocTitle()); |
168 | 0 | optionsMap.put(Preferences.KEYS.SHOW_ACTION_REQUESTED, preferences.getShowActionRequested()); |
169 | 0 | optionsMap.put(Preferences.KEYS.SHOW_INITIATOR, preferences.getShowInitiator()); |
170 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DELEGATOR, preferences.getShowDelegator()); |
171 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DATE_CREATED, preferences.getShowDateCreated()); |
172 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DOCUMENT_STATUS, preferences.getShowDocumentStatus()); |
173 | 0 | optionsMap.put(Preferences.KEYS.SHOW_APP_DOC_STATUS, preferences.getShowAppDocStatus()); |
174 | 0 | optionsMap.put(Preferences.KEYS.SHOW_GROUP_REQUEST, preferences.getShowWorkgroupRequest()); |
175 | 0 | optionsMap.put(Preferences.KEYS.SHOW_CLEAR_FYI, preferences.getShowClearFyi()); |
176 | 0 | optionsMap.put(Preferences.KEYS.PAGE_SIZE, preferences.getPageSize().trim()); |
177 | 0 | optionsMap.put(Preferences.KEYS.EMAIL_NOTIFICATION, preferences.getEmailNotification()); |
178 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_PRIMARY_DELEGATION, preferences.getNotifyPrimaryDelegation()); |
179 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_SECONDARY_DELEGATION, preferences.getNotifySecondaryDelegation()); |
180 | 0 | optionsMap.put(Preferences.KEYS.DELEGATOR_FILTER, preferences.getDelegatorFilter()); |
181 | 0 | optionsMap.put(Preferences.KEYS.PRIMARY_DELEGATE_FILTER, preferences.getPrimaryDelegateFilter()); |
182 | 0 | optionsMap.put(Preferences.KEYS.SHOW_DATE_APPROVED, preferences.getShowDateApproved()); |
183 | 0 | optionsMap.put(Preferences.KEYS.SHOW_CURRENT_NODE, preferences.getShowCurrentNode()); |
184 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_ACKNOWLEDGE, preferences.getNotifyAcknowledge()); |
185 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_APPROVE, preferences.getNotifyApprove()); |
186 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_COMPLETE, preferences.getNotifyComplete()); |
187 | 0 | optionsMap.put(Preferences.KEYS.NOTIFY_FYI, preferences.getNotifyFYI()); |
188 | 0 | if (ConfigContext.getCurrentContextConfig().getOutBoxOn()) { |
189 | 0 | optionsMap.put(Preferences.KEYS.USE_OUT_BOX, preferences.getUseOutbox()); |
190 | |
} |
191 | 0 | getUserOptionService().save(principalId, optionsMap); |
192 | 0 | if ( LOG.isDebugEnabled() ) { |
193 | 0 | LOG.debug("saved preferences user " + principalId); |
194 | |
} |
195 | 0 | } |
196 | |
|
197 | |
private void validate(Preferences preferences) { |
198 | 0 | LOG.debug("validating preferences"); |
199 | |
|
200 | 0 | Collection errors = new ArrayList(); |
201 | |
try { |
202 | 0 | new Integer(preferences.getRefreshRate().trim()); |
203 | 0 | } catch (NumberFormatException e) { |
204 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionList Refresh Rate must be in whole " + |
205 | |
"minutes", Preferences.KEYS.ERR_KEY_REFRESH_RATE_WHOLE_NUM)); |
206 | 0 | } catch (NullPointerException e1) { |
207 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionList Refresh Rate must be in whole " + |
208 | |
"minutes", Preferences.KEYS.ERR_KEY_REFRESH_RATE_WHOLE_NUM)); |
209 | 0 | } |
210 | |
|
211 | |
try { |
212 | 0 | if(new Integer(preferences.getPageSize().trim()) == 0){ |
213 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionList Page Size must be non-zero ", |
214 | |
Preferences.KEYS.ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM)); |
215 | |
} |
216 | 0 | } catch (NumberFormatException e) { |
217 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionList Page Size must be in whole " + |
218 | |
"minutes", Preferences.KEYS.ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM)); |
219 | 0 | } catch (NullPointerException e1) { |
220 | 0 | errors.add(new WorkflowServiceErrorImpl("ActionList Page Size must be in whole " + |
221 | |
"minutes", Preferences.KEYS.ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM)); |
222 | 0 | } |
223 | |
|
224 | 0 | LOG.debug("end validating preferences"); |
225 | 0 | if (! errors.isEmpty()) { |
226 | 0 | throw new WorkflowServiceErrorException("Preference Validation Error", errors); |
227 | |
} |
228 | 0 | } |
229 | |
|
230 | |
public UserOptionsService getUserOptionService() { |
231 | 0 | return (UserOptionsService) KEWServiceLocator.getService( |
232 | |
KEWServiceLocator.USER_OPTIONS_SRV); |
233 | |
} |
234 | |
|
235 | 0 | private final class UserOptionsWrapper { |
236 | |
|
237 | |
private final UserOptions userOptions; |
238 | |
private final boolean isSaveRequired; |
239 | |
|
240 | 0 | public UserOptionsWrapper(UserOptions userOptions, boolean isSaveRequired) { |
241 | 0 | this.userOptions = userOptions; |
242 | 0 | this.isSaveRequired = isSaveRequired; |
243 | 0 | } |
244 | |
|
245 | |
public UserOptions getUserOptions() { |
246 | 0 | return userOptions; |
247 | |
} |
248 | |
|
249 | |
public boolean isSaveRequired() { |
250 | 0 | return isSaveRequired; |
251 | |
} |
252 | |
} |
253 | |
} |
254 | |
|
255 | |
|