2013-02-06 15:40:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.workspace.server.util;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
2013-02-13 18:39:33 +01:00
|
|
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
2013-02-06 15:40:17 +01:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
|
|
|
|
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
|
|
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
2013-02-13 18:39:33 +01:00
|
|
|
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Federico De Faveri defaveri@isti.cnr.it
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class Util {
|
|
|
|
|
|
|
|
public static final String USERNAME_ATTRIBUTE = "username";
|
|
|
|
public static final String FOLDERIMPORTER_ATTRIBUTE = "FOLDER_IMPORTER";
|
|
|
|
public static final String METADATACONVERTER_ATTRIBUTE = "METADATA_CONVERTER";
|
|
|
|
public static final String WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE = "EVENT_COLLECTOR";
|
|
|
|
public static final String WORKSPACEBUILDER_ATTRIBUTE = "WORKSPACEBUILDER";
|
2013-02-13 18:39:33 +01:00
|
|
|
public static final String NOTIFICATION_MANAGER = "NOTIFICATIONMANAGER";
|
|
|
|
public static final String NOTIFICATION_PRODUCER = "NOTIFICATIONMANAGER";
|
|
|
|
|
|
|
|
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.wsmail.server.WsMailServiceImpl"; //IN DEV
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
// public static final String TEST_SCOPE = "/gcube/devsec";
|
|
|
|
// public static final String TEST_USER = "pasquale.pagano";
|
|
|
|
|
2013-02-12 16:02:00 +01:00
|
|
|
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
2013-02-06 15:40:17 +01:00
|
|
|
// public static final String TEST_USER = "federico.defaveri";
|
|
|
|
// public static final String TEST_USER = "massimiliano.assante";
|
|
|
|
// public static final String TEST_USER = "pasquale.pagano";
|
2013-02-13 18:39:33 +01:00
|
|
|
public static final String TEST_USER = "francesco.mangiacrapa";
|
|
|
|
public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
public static GCUBEClientLog defaultLogger = new GCUBEClientLog("WorkspacePortlet");
|
|
|
|
|
|
|
|
public static ASLSession getAslSession(HttpSession httpSession)
|
|
|
|
{
|
|
|
|
String sessionID = httpSession.getId();
|
|
|
|
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
defaultLogger.error("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND");
|
|
|
|
|
|
|
|
//for test only
|
|
|
|
httpSession.setAttribute(USERNAME_ATTRIBUTE, TEST_USER);
|
|
|
|
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, TEST_USER);
|
|
|
|
session.setScope(TEST_SCOPE);
|
2013-02-13 18:39:33 +01:00
|
|
|
session.setUserAvatarId(TEST_USER + "Avatar");
|
|
|
|
session.setUserFullName(TEST_USER_FULL_NAME);
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
|
|
|
|
{
|
|
|
|
final ASLSession session = getAslSession(httpSession);
|
|
|
|
|
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(session);
|
|
|
|
|
|
|
|
final GCUBELog logger = getLogger(workspace);
|
|
|
|
|
|
|
|
if (session.getAttribute(METADATACONVERTER_ATTRIBUTE) == null){
|
|
|
|
|
|
|
|
logger.trace("Initializing the Metadata converter");
|
|
|
|
|
|
|
|
Thread mcLoader = new Thread(new Runnable(){
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
MetadataConverter mc = new MetadataConverter(logger);
|
|
|
|
mc.setup(session);
|
|
|
|
session.setAttribute(METADATACONVERTER_ATTRIBUTE, mc);
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error initializing the Metadata Converter: "+e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
mcLoader.start();
|
|
|
|
}
|
|
|
|
if (session.getAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE) == null){
|
|
|
|
|
|
|
|
|
|
|
|
logger.trace("Initializing the event collector");
|
|
|
|
|
|
|
|
//we prepare the event collector
|
|
|
|
WorkspaceEventCollector eventCollector = new WorkspaceEventCollector(logger);
|
|
|
|
workspace.addWorkspaceListener(eventCollector);
|
|
|
|
session.setAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE, eventCollector);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null)
|
|
|
|
{
|
|
|
|
logger.trace("Initializing the workspace area builder");
|
|
|
|
|
|
|
|
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder(logger);
|
|
|
|
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return workspace;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GCUBELog getLogger(Workspace workspace)
|
|
|
|
{
|
|
|
|
/* TODO if (workspace instanceof PersistentFSWorkspace){
|
|
|
|
PersistentFSWorkspace persistentFSWorkspace = (PersistentFSWorkspace) workspace;
|
|
|
|
try {
|
|
|
|
return persistentFSWorkspace.getWorkspacePortletLogger();
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
return defaultLogger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MetadataConverter getMetadataConverter(GCUBELog logger, HttpSession httpSession)
|
|
|
|
{
|
|
|
|
MetadataConverter mc = (MetadataConverter) httpSession.getAttribute(METADATACONVERTER_ATTRIBUTE);
|
|
|
|
|
|
|
|
if (mc==null)
|
|
|
|
{
|
|
|
|
|
|
|
|
mc = new MetadataConverter(logger);
|
|
|
|
ASLSession session = getAslSession(httpSession);
|
|
|
|
mc.setup(session);
|
|
|
|
session.setAttribute(METADATACONVERTER_ATTRIBUTE, mc);
|
|
|
|
}
|
|
|
|
|
|
|
|
mc.isReady();
|
|
|
|
|
|
|
|
return mc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WorkspaceEventCollector getEventCollector(HttpSession httpSession)
|
|
|
|
{
|
|
|
|
ASLSession session = getAslSession(httpSession);
|
|
|
|
return (WorkspaceEventCollector) session.getAttribute(Util.WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GWTWorkspaceBuilder getGWTWorkspaceBuilder(HttpSession httpSession)
|
|
|
|
{
|
|
|
|
ASLSession session = getAslSession(httpSession);
|
|
|
|
return (GWTWorkspaceBuilder) session.getAttribute(Util.WORKSPACEBUILDER_ATTRIBUTE);
|
|
|
|
}
|
2013-02-13 18:39:33 +01:00
|
|
|
|
|
|
|
public static NotificationsManager getNotificationManager(ASLSession session)
|
|
|
|
{
|
|
|
|
|
|
|
|
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
|
|
|
|
|
|
|
|
if (notifMng == null) {
|
|
|
|
defaultLogger.trace("Create new NotificationsManager for user: "+session.getUsername());
|
|
|
|
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID);
|
|
|
|
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
|
|
|
|
}
|
|
|
|
|
|
|
|
return notifMng;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static NotificationsProducer getNotificationProducer(ASLSession session)
|
|
|
|
{
|
|
|
|
|
|
|
|
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
|
|
|
|
|
|
|
|
if (notifProducer == null) {
|
|
|
|
defaultLogger.trace("Create new Notification Producer for user: "+session.getUsername());
|
|
|
|
notifProducer = new NotificationsProducer(session);
|
|
|
|
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return notifProducer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getUserId(HttpSession httpSession) {
|
|
|
|
|
|
|
|
ASLSession session = getAslSession(httpSession);
|
|
|
|
|
|
|
|
return session.getUsername();
|
|
|
|
}
|
2013-02-06 15:40:17 +01:00
|
|
|
|
|
|
|
}
|