1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.view.admin; |
---|
31 | |
---|
32 | import org.springframework.beans.factory.annotation.Autowired; |
---|
33 | |
---|
34 | import static com.eventrouter.MessagePublisher.*; |
---|
35 | import com.eventrouter.annotation.Subscribe; |
---|
36 | |
---|
37 | import com.vaadin.terminal.Sizeable; |
---|
38 | import com.vaadin.terminal.ThemeResource; |
---|
39 | import com.vaadin.terminal.gwt.client.ui.AlignmentInfo.Bits; |
---|
40 | import com.vaadin.terminal.gwt.server.HttpServletRequestListener; |
---|
41 | import com.vaadin.ui.Alignment; |
---|
42 | import com.vaadin.ui.ComponentContainer; |
---|
43 | import com.vaadin.ui.Embedded; |
---|
44 | import com.vaadin.ui.GridLayout; |
---|
45 | import com.vaadin.ui.Label; |
---|
46 | import com.vaadin.ui.LoginForm; |
---|
47 | import com.vaadin.ui.LoginForm.LoginEvent; |
---|
48 | import com.vaadin.ui.VerticalLayout; |
---|
49 | import com.vaadin.ui.Window; |
---|
50 | import com.vaadin.ui.Window.Notification; |
---|
51 | import com.vaadin.ui.themes.Reindeer; |
---|
52 | |
---|
53 | import com.github.wolfie.refresher.Refresher; |
---|
54 | import com.github.wolfie.refresher.Refresher.RefreshListener; |
---|
55 | import com.github.wolfie.sessionguard.SessionGuard; |
---|
56 | |
---|
57 | import serpro.mailarchiver.service.dto.TSession; |
---|
58 | import serpro.mailarchiver.service.web.ArchiveServices; |
---|
59 | import serpro.mailarchiver.service.web.ServiceFault; |
---|
60 | import serpro.mailarchiver.session.Session; |
---|
61 | import serpro.mailarchiver.session.SessionMap; |
---|
62 | import serpro.mailarchiver.util.Logger; |
---|
63 | import serpro.mailarchiver.view.BaseApplication; |
---|
64 | |
---|
65 | public class AdminConsoleApp extends BaseApplication implements HttpServletRequestListener { |
---|
66 | |
---|
67 | private static final Logger log = Logger.getLocalLogger(); |
---|
68 | |
---|
69 | @Autowired |
---|
70 | private ArchiveServices archiveServices; |
---|
71 | |
---|
72 | private Session session; |
---|
73 | |
---|
74 | private Window mainWindow; |
---|
75 | |
---|
76 | private VerticalLayout loginVLo; |
---|
77 | private VerticalLayout mainWindowVLo; |
---|
78 | |
---|
79 | private Toolbar toolbar; |
---|
80 | |
---|
81 | private Config config; |
---|
82 | private Explore explore; |
---|
83 | private Search search; |
---|
84 | private Help help; |
---|
85 | private Upload upload; |
---|
86 | private ImportGears importGears; |
---|
87 | private Terminal terminal; |
---|
88 | |
---|
89 | private ComponentContainer currentContent; |
---|
90 | |
---|
91 | public static AdminConsoleApp getInstance() { |
---|
92 | return (AdminConsoleApp) BaseApplication.getInstance(); |
---|
93 | } |
---|
94 | |
---|
95 | public Session getSession() { |
---|
96 | return session; |
---|
97 | } |
---|
98 | |
---|
99 | @Override |
---|
100 | public void init() { |
---|
101 | |
---|
102 | setTheme("console"); |
---|
103 | |
---|
104 | mainWindow = new Window("MailArchiver Admin Console"); |
---|
105 | mainWindow.setName("admin_console"); |
---|
106 | |
---|
107 | setMainWindow(mainWindow); |
---|
108 | |
---|
109 | createLoginContent(); |
---|
110 | } |
---|
111 | |
---|
112 | @Subscribe({"/mailarchiver/logout"}) |
---|
113 | private void createLoginContent() { |
---|
114 | |
---|
115 | loginVLo = new VerticalLayout(); |
---|
116 | loginVLo.addStyleName(Reindeer.LAYOUT_BLACK); |
---|
117 | loginVLo.setSizeFull(); |
---|
118 | loginVLo.setMargin(true); |
---|
119 | |
---|
120 | GridLayout glo = new GridLayout(2, 2); |
---|
121 | glo.addStyleName(Reindeer.LAYOUT_WHITE); |
---|
122 | glo.setWidth("300px"); |
---|
123 | glo.setHeight("220px"); |
---|
124 | glo.setMargin(true); |
---|
125 | glo.setSpacing(false); |
---|
126 | |
---|
127 | Embedded logo = new Embedded("", new ThemeResource("toolbar/img/mailarchiver_logo.png")); |
---|
128 | logo.setSizeUndefined(); |
---|
129 | glo.addComponent(logo, 0, 0); |
---|
130 | glo.setComponentAlignment(logo, Alignment.TOP_CENTER); |
---|
131 | |
---|
132 | Label caption = new Label("<h2>Admin<br>Console</h2>"); |
---|
133 | caption.setSizeUndefined(); |
---|
134 | caption.setContentMode(Label.CONTENT_XHTML); |
---|
135 | glo.addComponent(caption, 1, 0); |
---|
136 | glo.setComponentAlignment(caption, Alignment.MIDDLE_LEFT); |
---|
137 | |
---|
138 | LoginForm login = new AdminConsoleLoginForm(); |
---|
139 | login.setSizeFull(); |
---|
140 | login.setUsernameCaption("User: "); |
---|
141 | login.setPasswordCaption("Password: "); |
---|
142 | |
---|
143 | login.addListener(new LoginForm.LoginListener() { |
---|
144 | @Override |
---|
145 | public void onLogin(LoginEvent event) { |
---|
146 | String username = event.getLoginParameter("username"); |
---|
147 | String password = event.getLoginParameter("password"); |
---|
148 | |
---|
149 | try { |
---|
150 | TSession sessionDto = archiveServices.login(username, password, null, null); |
---|
151 | |
---|
152 | if(sessionDto != null) { |
---|
153 | session = SessionMap.get(sessionDto.getId()); |
---|
154 | createMainContent(); |
---|
155 | showHumanizedNotification("New session for user " + username); |
---|
156 | } |
---|
157 | else { |
---|
158 | showErrorNotification("Wrong password or unknown user"); |
---|
159 | } |
---|
160 | } |
---|
161 | catch (ServiceFault ex) { |
---|
162 | log.error(ex); |
---|
163 | } |
---|
164 | } |
---|
165 | }); |
---|
166 | |
---|
167 | glo.addComponent(login, 0, 1, 1, 1); |
---|
168 | glo.setRowExpandRatio(1, 1.0f); |
---|
169 | |
---|
170 | loginVLo.addComponent(glo); |
---|
171 | loginVLo.setComponentAlignment(glo, new Alignment( |
---|
172 | Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_HORIZONTAL_CENTER)); |
---|
173 | |
---|
174 | mainWindow.setContent(loginVLo); |
---|
175 | } |
---|
176 | |
---|
177 | private void createMainContent() { |
---|
178 | |
---|
179 | mainWindowVLo = new VerticalLayout(); |
---|
180 | mainWindowVLo.setMargin(false); |
---|
181 | mainWindowVLo.setSpacing(false); |
---|
182 | |
---|
183 | final SessionGuard sessionGuard = new SessionGuard(); |
---|
184 | sessionGuard.setKeepalive(true); |
---|
185 | mainWindowVLo.addComponent(sessionGuard); |
---|
186 | |
---|
187 | final Refresher refresher = new Refresher(); |
---|
188 | refresher.addListener(new RefreshListener() { |
---|
189 | @Override |
---|
190 | public void refresh(Refresher source) { |
---|
191 | publish("/mailarchiver/refresh"); |
---|
192 | } |
---|
193 | }); |
---|
194 | mainWindowVLo.addComponent(refresher); |
---|
195 | |
---|
196 | toolbar = new Toolbar(); |
---|
197 | mainWindowVLo.addComponent(toolbar); |
---|
198 | |
---|
199 | // config = new Config(); |
---|
200 | // config.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
201 | // mainWindowVLo.addComponent(config); |
---|
202 | |
---|
203 | // explore = new Explore(); |
---|
204 | // explore.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
205 | // mainWindowVLo.addComponent(explore); |
---|
206 | |
---|
207 | search = new Search(); |
---|
208 | search.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
209 | mainWindowVLo.addComponent(search); |
---|
210 | |
---|
211 | // help = new Help(); |
---|
212 | // help.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
213 | // mainWindowVLo.addComponent(help); |
---|
214 | |
---|
215 | upload = new Upload(); |
---|
216 | upload.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
217 | mainWindowVLo.addComponent(upload); |
---|
218 | |
---|
219 | importGears = new ImportGears(); |
---|
220 | importGears.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
221 | mainWindowVLo.addComponent(importGears); |
---|
222 | |
---|
223 | terminal = new Terminal(); |
---|
224 | terminal.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
225 | mainWindowVLo.addComponent(terminal); |
---|
226 | |
---|
227 | mainWindow.setContent(mainWindowVLo); |
---|
228 | |
---|
229 | showImportGears(); |
---|
230 | } |
---|
231 | |
---|
232 | private void setContent(ComponentContainer newContent) { |
---|
233 | if((newContent != null) && (newContent != currentContent)) { |
---|
234 | |
---|
235 | if(currentContent != null) { |
---|
236 | currentContent.setHeight(0, Sizeable.UNITS_PIXELS); |
---|
237 | } |
---|
238 | |
---|
239 | newContent.setHeight(Sizeable.SIZE_UNDEFINED, Sizeable.UNITS_PIXELS); |
---|
240 | currentContent = newContent; |
---|
241 | mainWindowVLo.requestRepaintAll(); |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | //<editor-fold defaultstate="collapsed" desc=" switch panel "> |
---|
247 | |
---|
248 | @Subscribe({"/mailarchiver/action/show_config"}) |
---|
249 | private void showConfig() { |
---|
250 | setContent(config); |
---|
251 | } |
---|
252 | |
---|
253 | @Subscribe({"/mailarchiver/action/show_explore"}) |
---|
254 | private void showExplore() { |
---|
255 | setContent(explore); |
---|
256 | } |
---|
257 | |
---|
258 | @Subscribe({"/mailarchiver/action/show_search"}) |
---|
259 | private void showSearch() { |
---|
260 | setContent(search); |
---|
261 | } |
---|
262 | |
---|
263 | @Subscribe({"/mailarchiver/action/show_help"}) |
---|
264 | private void showHelp() { |
---|
265 | setContent(help); |
---|
266 | } |
---|
267 | |
---|
268 | @Subscribe({"/mailarchiver/action/show_upload"}) |
---|
269 | private void showUpload() { |
---|
270 | setContent(upload); |
---|
271 | } |
---|
272 | |
---|
273 | @Subscribe({"/mailarchiver/action/show_importGears"}) |
---|
274 | private void showImportGears() { |
---|
275 | setContent(importGears); |
---|
276 | } |
---|
277 | |
---|
278 | @Subscribe({"/mailarchiver/action/show_terminal"}) |
---|
279 | private void showTerminal() { |
---|
280 | setContent(terminal); |
---|
281 | } |
---|
282 | //</editor-fold> |
---|
283 | |
---|
284 | |
---|
285 | //<editor-fold defaultstate="collapsed" desc=" notifications "> |
---|
286 | |
---|
287 | @Subscribe({"/mailarchiver/notification/error"}) |
---|
288 | private void showErrorNotification(String caption) { |
---|
289 | Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE); |
---|
290 | getMainWindow().showNotification(n); |
---|
291 | } |
---|
292 | |
---|
293 | @Subscribe({"/mailarchiver/notification/error"}) |
---|
294 | private void showErrorNotification(String caption, String description) { |
---|
295 | Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE); |
---|
296 | n.setDescription(description); |
---|
297 | getMainWindow().showNotification(n); |
---|
298 | } |
---|
299 | |
---|
300 | @Subscribe({"/mailarchiver/notification/error"}) |
---|
301 | private void showErrorNotification(String caption, int position) { |
---|
302 | Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE); |
---|
303 | n.setPosition(position); |
---|
304 | getMainWindow().showNotification(n); |
---|
305 | } |
---|
306 | |
---|
307 | @Subscribe({"/mailarchiver/notification/error"}) |
---|
308 | private void showErrorNotification(String caption, String description, int position) { |
---|
309 | Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE); |
---|
310 | n.setDescription(description); |
---|
311 | n.setPosition(position); |
---|
312 | getMainWindow().showNotification(n); |
---|
313 | } |
---|
314 | |
---|
315 | //-------------------------------------------------------------------------- |
---|
316 | @Subscribe({"/mailarchiver/notification/warning"}) |
---|
317 | private void showWarningNotification(String caption) { |
---|
318 | Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE); |
---|
319 | getMainWindow().showNotification(n); |
---|
320 | } |
---|
321 | |
---|
322 | @Subscribe({"/mailarchiver/notification/warning"}) |
---|
323 | private void showWarningNotification(String caption, String description) { |
---|
324 | Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE); |
---|
325 | n.setDescription(description); |
---|
326 | getMainWindow().showNotification(n); |
---|
327 | } |
---|
328 | |
---|
329 | @Subscribe({"/mailarchiver/notification/warning"}) |
---|
330 | private void showWarningNotification(String caption, int position) { |
---|
331 | Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE); |
---|
332 | n.setPosition(position); |
---|
333 | getMainWindow().showNotification(n); |
---|
334 | } |
---|
335 | |
---|
336 | @Subscribe({"/mailarchiver/notification/warning"}) |
---|
337 | private void showWarningNotification(String caption, String description, int position) { |
---|
338 | Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE); |
---|
339 | n.setDescription(description); |
---|
340 | n.setPosition(position); |
---|
341 | getMainWindow().showNotification(n); |
---|
342 | } |
---|
343 | |
---|
344 | //-------------------------------------------------------------------------- |
---|
345 | @Subscribe({"/mailarchiver/notification/humanized"}) |
---|
346 | private void showHumanizedNotification(String caption) { |
---|
347 | Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE); |
---|
348 | getMainWindow().showNotification(n); |
---|
349 | } |
---|
350 | |
---|
351 | @Subscribe({"/mailarchiver/notification/humanized"}) |
---|
352 | private void showHumanizedNotification(String caption, String description) { |
---|
353 | Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE); |
---|
354 | n.setDescription(description); |
---|
355 | getMainWindow().showNotification(n); |
---|
356 | } |
---|
357 | |
---|
358 | @Subscribe({"/mailarchiver/notification/humanized"}) |
---|
359 | private void showHumanizedNotification(String caption, int position) { |
---|
360 | Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE); |
---|
361 | n.setPosition(position); |
---|
362 | getMainWindow().showNotification(n); |
---|
363 | } |
---|
364 | |
---|
365 | @Subscribe({"/mailarchiver/notification/humanized"}) |
---|
366 | private void showHumanizedNotification(String caption, String description, int position) { |
---|
367 | Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE); |
---|
368 | n.setDescription(description); |
---|
369 | n.setPosition(position); |
---|
370 | getMainWindow().showNotification(n); |
---|
371 | } |
---|
372 | |
---|
373 | //-------------------------------------------------------------------------- |
---|
374 | @Subscribe({"/mailarchiver/notification/tray"}) |
---|
375 | private void showTrayNotification(String caption) { |
---|
376 | Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION); |
---|
377 | getMainWindow().showNotification(n); |
---|
378 | } |
---|
379 | |
---|
380 | @Subscribe({"/mailarchiver/notification/tray"}) |
---|
381 | private void showTrayNotification(String caption, String description) { |
---|
382 | Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION); |
---|
383 | n.setDescription(description); |
---|
384 | getMainWindow().showNotification(n); |
---|
385 | } |
---|
386 | |
---|
387 | @Subscribe({"/mailarchiver/notification/tray"}) |
---|
388 | private void showTrayNotification(String caption, int position) { |
---|
389 | Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION); |
---|
390 | n.setPosition(position); |
---|
391 | getMainWindow().showNotification(n); |
---|
392 | } |
---|
393 | |
---|
394 | @Subscribe({"/mailarchiver/notification/tray"}) |
---|
395 | private void showTrayNotification(String caption, String description, int position) { |
---|
396 | Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION); |
---|
397 | n.setDescription(description); |
---|
398 | n.setPosition(position); |
---|
399 | getMainWindow().showNotification(n); |
---|
400 | } |
---|
401 | //</editor-fold> |
---|
402 | |
---|
403 | |
---|
404 | } |
---|