1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kcb.web.spring; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.kuali.rice.kcb.bo.RecipientDelivererConfig; |
20 | |
import org.kuali.rice.kcb.deliverer.MessageDeliverer; |
21 | |
import org.kuali.rice.kcb.exception.ErrorList; |
22 | |
import org.kuali.rice.kcb.service.KENIntegrationService; |
23 | |
import org.kuali.rice.kcb.service.MessageDelivererRegistryService; |
24 | |
import org.kuali.rice.kcb.service.RecipientPreferenceService; |
25 | |
import org.springframework.beans.factory.annotation.Required; |
26 | |
import org.springframework.web.servlet.ModelAndView; |
27 | |
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
28 | |
|
29 | |
import javax.servlet.ServletException; |
30 | |
import javax.servlet.http.HttpServletRequest; |
31 | |
import javax.servlet.http.HttpServletResponse; |
32 | |
import java.io.IOException; |
33 | |
import java.util.ArrayList; |
34 | |
import java.util.Collection; |
35 | |
import java.util.HashMap; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class UserPreferencesController extends MultiActionController { |
43 | |
|
44 | 0 | private static final Logger LOG = Logger.getLogger(UserPreferencesController.class); |
45 | |
|
46 | |
private static final String VIEW = "DelivererPreferences"; |
47 | |
private static final String KEW_CHANNEL = "KEW"; |
48 | |
protected RecipientPreferenceService recipientPreferenceService; |
49 | |
protected MessageDelivererRegistryService messageDelivererRegistryService; |
50 | |
protected KENIntegrationService kenIntegrationService; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Required |
57 | |
public void setRecipientPreferenceService(RecipientPreferenceService userPreferenceService) { |
58 | 0 | this.recipientPreferenceService = userPreferenceService; |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
@Required |
66 | |
public void setMessageDelivererRegistryService(MessageDelivererRegistryService messageDelivererRegistryService) { |
67 | 0 | this.messageDelivererRegistryService = messageDelivererRegistryService; |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@Required |
75 | |
public void setKenIntegrationService(KENIntegrationService kis) { |
76 | 0 | this.kenIntegrationService = kis; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
protected Collection<String> getAllChannels() { |
83 | |
|
84 | 0 | Collection<String> allChannels = new ArrayList<String>(); |
85 | |
|
86 | 0 | allChannels.addAll(kenIntegrationService.getAllChannelNames()); |
87 | 0 | return allChannels; |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public ModelAndView displayDelivererConfigurationForm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
100 | 0 | String userid = request.getRemoteUser(); |
101 | 0 | LOG.debug("remoteUser: "+userid); |
102 | |
|
103 | |
|
104 | 0 | Collection<MessageDeliverer> deliveryTypes = this.messageDelivererRegistryService.getAllDeliverers(); |
105 | |
|
106 | |
|
107 | 0 | Collection<String> channels = getAllChannels(); |
108 | |
|
109 | |
|
110 | 0 | HashMap<String, String> preferences = this.recipientPreferenceService.getRecipientPreferences(userid); |
111 | |
|
112 | |
|
113 | 0 | Collection<RecipientDelivererConfig> currentDeliverers = this.recipientPreferenceService.getDeliverersForRecipient(userid); |
114 | |
|
115 | 0 | Map<String, Boolean> currentDeliverersMap = new HashMap<String, Boolean>(); |
116 | 0 | for (RecipientDelivererConfig udc: currentDeliverers) { |
117 | 0 | String channelName = udc.getChannel(); |
118 | 0 | currentDeliverersMap.put(udc.getDelivererName() + "." + channelName, Boolean.TRUE); |
119 | 0 | } |
120 | |
|
121 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
122 | 0 | model.put("channels", channels); |
123 | 0 | model.put("deliveryTypes", deliveryTypes); |
124 | 0 | model.put("preferences", preferences); |
125 | 0 | model.put("currentDeliverersMap", currentDeliverersMap); |
126 | 0 | return new ModelAndView(VIEW, model); |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public ModelAndView saveDelivererConfiguration(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
138 | 0 | String userid = request.getRemoteUser(); |
139 | 0 | LOG.debug("remoteUser: "+userid); |
140 | 0 | boolean error = false; |
141 | |
|
142 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
143 | |
|
144 | |
|
145 | 0 | HashMap<String, String> preferences = new HashMap<String, String>(); |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | 0 | Collection<MessageDeliverer> deliveryTypes = this.messageDelivererRegistryService.getAllDeliverers(); |
152 | |
|
153 | |
|
154 | 0 | this.recipientPreferenceService.removeRecipientDelivererConfigs(userid); |
155 | |
|
156 | 0 | for (MessageDeliverer dt: deliveryTypes) { |
157 | 0 | String deliveryTypeName = dt.getName(); |
158 | 0 | HashMap<String,String> prefMap = dt.getPreferenceKeys(); |
159 | 0 | LOG.debug("deliveryName: "+deliveryTypeName); |
160 | 0 | HashMap<String, String> userprefs = new HashMap<String, String>(); |
161 | 0 | for (String prefKey:prefMap.keySet()) { |
162 | 0 | LOG.debug(" key: "+prefKey+", value: "+request.getParameter(deliveryTypeName+"."+prefKey)); |
163 | 0 | userprefs.put(deliveryTypeName+"."+prefKey, request.getParameter(deliveryTypeName+"."+prefKey )); |
164 | 0 | preferences.put(deliveryTypeName+"."+prefKey, request.getParameter(deliveryTypeName+"."+prefKey )); |
165 | |
} |
166 | |
try { |
167 | 0 | this.recipientPreferenceService.saveRecipientPreferences(userid, userprefs, dt); |
168 | 0 | } catch (ErrorList errorlist) { |
169 | 0 | error = true; |
170 | 0 | model.put("errorList", errorlist.getErrors()) ; |
171 | 0 | } |
172 | |
|
173 | |
|
174 | 0 | String[] channels = request.getParameterValues(deliveryTypeName+".channels"); |
175 | 0 | if (channels != null && channels.length > 0) { |
176 | 0 | for (int j=0; j < channels.length; j++) { |
177 | 0 | LOG.debug(deliveryTypeName+".channels["+j+"] "+channels[j]); |
178 | |
} |
179 | |
} |
180 | |
|
181 | 0 | this.recipientPreferenceService.saveRecipientDelivererConfig(userid, deliveryTypeName, channels); |
182 | 0 | } |
183 | |
|
184 | |
|
185 | 0 | Collection<String> channels = getAllChannels(); |
186 | |
|
187 | |
|
188 | 0 | Collection<RecipientDelivererConfig> currentDeliverers = this.recipientPreferenceService.getDeliverersForRecipient(userid); |
189 | 0 | Map<String, Object> currentDeliverersMap = new HashMap<String, Object>(); |
190 | 0 | for (RecipientDelivererConfig udc: currentDeliverers) { |
191 | 0 | String channelId = udc.getChannel(); |
192 | 0 | currentDeliverersMap.put(udc.getDelivererName()+"."+channelId, Boolean.TRUE); |
193 | 0 | } |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | 0 | model.put("channels", channels); |
204 | 0 | model.put("deliveryTypes", deliveryTypes); |
205 | 0 | model.put("preferences", preferences); |
206 | 0 | model.put("currentDeliverersMap", currentDeliverersMap); |
207 | 0 | model.put("message", "Update Successful"); |
208 | |
|
209 | 0 | return new ModelAndView(VIEW, model); |
210 | |
} |
211 | |
} |