1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ken.web.spring; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.Collection; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.servlet.ServletException; |
24 | |
import javax.servlet.http.HttpServletRequest; |
25 | |
import javax.servlet.http.HttpServletResponse; |
26 | |
|
27 | |
import org.apache.log4j.Logger; |
28 | |
import org.kuali.rice.ken.bo.NotificationContentType; |
29 | |
import org.kuali.rice.ken.service.NotificationAuthorizationService; |
30 | |
import org.kuali.rice.ken.service.NotificationContentTypeService; |
31 | |
import org.kuali.rice.ken.service.NotificationService; |
32 | |
import org.springframework.web.servlet.ModelAndView; |
33 | |
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class ContentTypeController extends MultiActionController { |
40 | |
|
41 | 0 | private static String view = ""; |
42 | |
protected NotificationService notificationService; |
43 | |
protected NotificationContentTypeService notificationContentTypeService; |
44 | |
protected NotificationAuthorizationService notificationAuthzService; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public void setNotificationService(NotificationService notificationService) { |
51 | 0 | this.notificationService = notificationService; |
52 | 0 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public void setNotificationContentTypeService(NotificationContentTypeService notificationContentTypeService) { |
59 | 0 | this.notificationContentTypeService = notificationContentTypeService; |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setNotificationAuthorizationService(NotificationAuthorizationService notificationAuthzService) { |
67 | 0 | this.notificationAuthzService = notificationAuthzService; |
68 | 0 | } |
69 | |
|
70 | |
|
71 | 0 | private static final Logger LOG = Logger.getLogger(NotificationController.class); |
72 | |
|
73 | |
@Override |
74 | |
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
75 | |
|
76 | |
|
77 | 0 | String user = request.getRemoteUser(); |
78 | 0 | if (!notificationAuthzService.isUserAdministrator(user)) { |
79 | 0 | response.setStatus(HttpServletResponse.SC_FORBIDDEN); |
80 | |
|
81 | 0 | throw new SecurityException("User " + user + " is not a Notification System administrator"); |
82 | |
} |
83 | 0 | return super.handleRequestInternal(request, response); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public ModelAndView displayContentTypes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
95 | |
|
96 | 0 | view = "ContentTypeManager"; |
97 | |
|
98 | 0 | Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes(); |
99 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
100 | 0 | model.put("contentTypes", contentTypes); |
101 | 0 | return new ModelAndView(view, model); |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public ModelAndView displayContentTypeForm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
113 | |
|
114 | 0 | view = "ContentTypeForm"; |
115 | |
NotificationContentType notificationContentType; |
116 | |
String actionrequested; |
117 | 0 | String name = request.getParameter("name"); |
118 | 0 | LOG.debug("name param: "+name); |
119 | |
|
120 | 0 | if (name == null) { |
121 | 0 | actionrequested = new String("add"); |
122 | 0 | notificationContentType = new NotificationContentType(); |
123 | |
} else { |
124 | 0 | actionrequested = new String("update"); |
125 | 0 | notificationContentType = this.notificationContentTypeService.getNotificationContentType(name); |
126 | |
} |
127 | |
|
128 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
129 | 0 | model.put("notificationContentType",notificationContentType); |
130 | 0 | model.put("actionrequested", actionrequested); |
131 | 0 | return new ModelAndView(view, model); |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public ModelAndView addContentType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
143 | 0 | view = "ContentTypeManager"; |
144 | 0 | String id = request.getParameter("id"); |
145 | 0 | String name = request.getParameter("name"); |
146 | 0 | String description = request.getParameter("description"); |
147 | 0 | String namespace = request.getParameter("namespace"); |
148 | 0 | String xsd = request.getParameter("xsd"); |
149 | 0 | String xsl = request.getParameter("xsl"); |
150 | |
|
151 | 0 | LOG.debug("id: "+id); |
152 | 0 | LOG.debug("name: "+name); |
153 | 0 | LOG.debug("description: "+description); |
154 | 0 | LOG.debug("namespace: "+namespace); |
155 | 0 | LOG.debug("xsd: "+xsd); |
156 | 0 | LOG.debug("xsl: "+xsl); |
157 | |
|
158 | 0 | NotificationContentType notificationContentType = new NotificationContentType(); |
159 | 0 | notificationContentType.setName(name); |
160 | 0 | notificationContentType.setDescription(description); |
161 | 0 | notificationContentType.setNamespace(namespace); |
162 | 0 | notificationContentType.setXsd(xsd); |
163 | 0 | notificationContentType.setXsl(xsl); |
164 | |
|
165 | 0 | this.notificationContentTypeService.saveNotificationContentType(notificationContentType); |
166 | |
|
167 | 0 | Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes(); |
168 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
169 | 0 | model.put("contentTypes", contentTypes); |
170 | 0 | return new ModelAndView(view, model); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public ModelAndView updateContentType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
182 | 0 | view = "ContentTypeManager"; |
183 | 0 | String id = request.getParameter("id"); |
184 | 0 | String name = request.getParameter("name"); |
185 | 0 | String description = request.getParameter("description"); |
186 | 0 | String namespace = request.getParameter("namespace"); |
187 | 0 | String xsd = request.getParameter("xsd"); |
188 | 0 | String xsl = request.getParameter("xsl"); |
189 | |
|
190 | 0 | LOG.debug("id: "+id); |
191 | 0 | LOG.debug("name: "+name); |
192 | 0 | LOG.debug("description: "+description); |
193 | 0 | LOG.debug("namespace: "+namespace); |
194 | 0 | LOG.debug("xsd: "+xsd); |
195 | 0 | LOG.debug("xsl: "+xsl); |
196 | |
|
197 | 0 | NotificationContentType notificationContentType = this.notificationContentTypeService.getNotificationContentType(name); |
198 | |
|
199 | 0 | notificationContentType.setName(name); |
200 | 0 | notificationContentType.setDescription(description); |
201 | 0 | notificationContentType.setNamespace(namespace); |
202 | 0 | notificationContentType.setXsd(xsd); |
203 | 0 | notificationContentType.setXsl(xsl); |
204 | |
|
205 | 0 | this.notificationContentTypeService.saveNotificationContentType(notificationContentType); |
206 | |
|
207 | |
|
208 | |
|
209 | 0 | Collection<NotificationContentType> contentTypes = this.notificationContentTypeService.getAllCurrentContentTypes(); |
210 | 0 | Map<String, Object> model = new HashMap<String, Object>(); |
211 | 0 | model.put("contentTypes", contentTypes); |
212 | 0 | return new ModelAndView(view, model); |
213 | |
} |
214 | |
} |