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