/* Copyright 2011 Massimo Gengarelli <gengarel@cs.unibo.it>
* This file is part of Floz Configurator.
* Floz Configurator is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Floz Configurator 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Floz Configurator. If not, see http://www.gnu.org/licenses/.
*/
package it.unibo.cs.v2.server;
import java.io.File;
import it.unibo.cs.v2.servlets.RemoveNotification;
import it.unibo.cs.v2.shared.Notification;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@SuppressWarnings("serial")
public class RemoveNotificationImpl extends RemoteServiceServlet implements RemoveNotification {
@Override
public void removeNotification(Notification n) throws Exception {
String login = (String) getThreadLocalRequest().getSession().getAttribute("login");
String home = (String) getThreadLocalRequest().getSession().getAttribute("home");
if (login.equals("") || home.equals(""))
throw new Exception("Session expired, please refresh the page.");
VirtuaLogger logger = new VirtuaLogger(home, this.getClass().getName());
logger.log("Removing notification " + n.getFileName());
File notificationFile = new File(getServletContext().getRealPath("users/" + login + "/" + n.getFileName()));
synchronized (this) {
if (notificationFile.exists())
notificationFile.delete();
else
throw new Exception("Notification file not found.");
}
logger.log("Removed notification " + n.getFileName());
}
}