/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.view.admin;
import org.springframework.beans.factory.annotation.Autowired;
import static com.eventrouter.MessagePublisher.*;
import com.eventrouter.annotation.Subscribe;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.gwt.client.ui.AlignmentInfo.Bits;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.LoginForm.LoginEvent;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.themes.Reindeer;
import com.github.wolfie.refresher.Refresher;
import com.github.wolfie.refresher.Refresher.RefreshListener;
import com.github.wolfie.sessionguard.SessionGuard;
import serpro.mailarchiver.service.dto.TSession;
import serpro.mailarchiver.service.web.ArchiveServices;
import serpro.mailarchiver.service.web.ServiceFault;
import serpro.mailarchiver.session.Session;
import serpro.mailarchiver.session.SessionMap;
import serpro.mailarchiver.util.Logger;
import serpro.mailarchiver.view.BaseApplication;
public class AdminConsoleApp extends BaseApplication implements HttpServletRequestListener {
private static final Logger log = Logger.getLocalLogger();
@Autowired
private ArchiveServices archiveServices;
private Session session;
private Window mainWindow;
private VerticalLayout loginVLo;
private VerticalLayout mainWindowVLo;
private Toolbar toolbar;
private Config config;
private Explore explore;
private Search search;
private Help help;
private Upload upload;
private ImportGears importGears;
private Terminal terminal;
private ComponentContainer currentContent;
public static AdminConsoleApp getInstance() {
return (AdminConsoleApp) BaseApplication.getInstance();
}
public Session getSession() {
return session;
}
@Override
public void init() {
setTheme("console");
mainWindow = new Window("MailArchiver Admin Console");
mainWindow.setName("admin_console");
setMainWindow(mainWindow);
createLoginContent();
}
@Subscribe({"/mailarchiver/logout"})
private void createLoginContent() {
loginVLo = new VerticalLayout();
loginVLo.addStyleName(Reindeer.LAYOUT_BLACK);
loginVLo.setSizeFull();
loginVLo.setMargin(true);
GridLayout glo = new GridLayout(2, 2);
glo.addStyleName(Reindeer.LAYOUT_WHITE);
glo.setWidth("300px");
glo.setHeight("220px");
glo.setMargin(true);
glo.setSpacing(false);
Embedded logo = new Embedded("", new ThemeResource("toolbar/img/mailarchiver_logo.png"));
logo.setSizeUndefined();
glo.addComponent(logo, 0, 0);
glo.setComponentAlignment(logo, Alignment.TOP_CENTER);
Label caption = new Label("
Admin
Console
");
caption.setSizeUndefined();
caption.setContentMode(Label.CONTENT_XHTML);
glo.addComponent(caption, 1, 0);
glo.setComponentAlignment(caption, Alignment.MIDDLE_LEFT);
LoginForm login = new AdminConsoleLoginForm();
login.setSizeFull();
login.setUsernameCaption("User: ");
login.setPasswordCaption("Password: ");
login.addListener(new LoginForm.LoginListener() {
@Override
public void onLogin(LoginEvent event) {
String username = event.getLoginParameter("username");
String password = event.getLoginParameter("password");
try {
TSession sessionDto = archiveServices.login(username, password, null, null);
if(sessionDto != null) {
session = SessionMap.get(sessionDto.getId());
createMainContent();
showHumanizedNotification("New session for user " + username);
}
else {
showErrorNotification("Wrong password or unknown user");
}
}
catch (ServiceFault ex) {
log.error(ex);
}
}
});
glo.addComponent(login, 0, 1, 1, 1);
glo.setRowExpandRatio(1, 1.0f);
loginVLo.addComponent(glo);
loginVLo.setComponentAlignment(glo, new Alignment(
Bits.ALIGNMENT_VERTICAL_CENTER | Bits.ALIGNMENT_HORIZONTAL_CENTER));
mainWindow.setContent(loginVLo);
}
private void createMainContent() {
mainWindowVLo = new VerticalLayout();
mainWindowVLo.setMargin(false);
mainWindowVLo.setSpacing(false);
final SessionGuard sessionGuard = new SessionGuard();
sessionGuard.setKeepalive(true);
mainWindowVLo.addComponent(sessionGuard);
final Refresher refresher = new Refresher();
refresher.addListener(new RefreshListener() {
@Override
public void refresh(Refresher source) {
publish("/mailarchiver/refresh");
}
});
mainWindowVLo.addComponent(refresher);
toolbar = new Toolbar();
mainWindowVLo.addComponent(toolbar);
// config = new Config();
// config.setHeight(0, Sizeable.UNITS_PIXELS);
// mainWindowVLo.addComponent(config);
// explore = new Explore();
// explore.setHeight(0, Sizeable.UNITS_PIXELS);
// mainWindowVLo.addComponent(explore);
search = new Search();
search.setHeight(0, Sizeable.UNITS_PIXELS);
mainWindowVLo.addComponent(search);
// help = new Help();
// help.setHeight(0, Sizeable.UNITS_PIXELS);
// mainWindowVLo.addComponent(help);
upload = new Upload();
upload.setHeight(0, Sizeable.UNITS_PIXELS);
mainWindowVLo.addComponent(upload);
importGears = new ImportGears();
importGears.setHeight(0, Sizeable.UNITS_PIXELS);
mainWindowVLo.addComponent(importGears);
terminal = new Terminal();
terminal.setHeight(0, Sizeable.UNITS_PIXELS);
mainWindowVLo.addComponent(terminal);
mainWindow.setContent(mainWindowVLo);
showImportGears();
}
private void setContent(ComponentContainer newContent) {
if((newContent != null) && (newContent != currentContent)) {
if(currentContent != null) {
currentContent.setHeight(0, Sizeable.UNITS_PIXELS);
}
newContent.setHeight(Sizeable.SIZE_UNDEFINED, Sizeable.UNITS_PIXELS);
currentContent = newContent;
mainWindowVLo.requestRepaintAll();
}
}
//
@Subscribe({"/mailarchiver/action/show_config"})
private void showConfig() {
setContent(config);
}
@Subscribe({"/mailarchiver/action/show_explore"})
private void showExplore() {
setContent(explore);
}
@Subscribe({"/mailarchiver/action/show_search"})
private void showSearch() {
setContent(search);
}
@Subscribe({"/mailarchiver/action/show_help"})
private void showHelp() {
setContent(help);
}
@Subscribe({"/mailarchiver/action/show_upload"})
private void showUpload() {
setContent(upload);
}
@Subscribe({"/mailarchiver/action/show_importGears"})
private void showImportGears() {
setContent(importGears);
}
@Subscribe({"/mailarchiver/action/show_terminal"})
private void showTerminal() {
setContent(terminal);
}
//
//
@Subscribe({"/mailarchiver/notification/error"})
private void showErrorNotification(String caption) {
Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/error"})
private void showErrorNotification(String caption, String description) {
Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE);
n.setDescription(description);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/error"})
private void showErrorNotification(String caption, int position) {
Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE);
n.setPosition(position);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/error"})
private void showErrorNotification(String caption, String description, int position) {
Notification n = new Notification(caption, Notification.TYPE_ERROR_MESSAGE);
n.setDescription(description);
n.setPosition(position);
getMainWindow().showNotification(n);
}
//--------------------------------------------------------------------------
@Subscribe({"/mailarchiver/notification/warning"})
private void showWarningNotification(String caption) {
Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/warning"})
private void showWarningNotification(String caption, String description) {
Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE);
n.setDescription(description);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/warning"})
private void showWarningNotification(String caption, int position) {
Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE);
n.setPosition(position);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/warning"})
private void showWarningNotification(String caption, String description, int position) {
Notification n = new Notification(caption, Notification.TYPE_WARNING_MESSAGE);
n.setDescription(description);
n.setPosition(position);
getMainWindow().showNotification(n);
}
//--------------------------------------------------------------------------
@Subscribe({"/mailarchiver/notification/humanized"})
private void showHumanizedNotification(String caption) {
Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/humanized"})
private void showHumanizedNotification(String caption, String description) {
Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE);
n.setDescription(description);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/humanized"})
private void showHumanizedNotification(String caption, int position) {
Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE);
n.setPosition(position);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/humanized"})
private void showHumanizedNotification(String caption, String description, int position) {
Notification n = new Notification(caption, Notification.TYPE_HUMANIZED_MESSAGE);
n.setDescription(description);
n.setPosition(position);
getMainWindow().showNotification(n);
}
//--------------------------------------------------------------------------
@Subscribe({"/mailarchiver/notification/tray"})
private void showTrayNotification(String caption) {
Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/tray"})
private void showTrayNotification(String caption, String description) {
Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION);
n.setDescription(description);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/tray"})
private void showTrayNotification(String caption, int position) {
Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION);
n.setPosition(position);
getMainWindow().showNotification(n);
}
@Subscribe({"/mailarchiver/notification/tray"})
private void showTrayNotification(String caption, String description, int position) {
Notification n = new Notification(caption, Notification.TYPE_TRAY_NOTIFICATION);
n.setDescription(description);
n.setPosition(position);
getMainWindow().showNotification(n);
}
//
}