package org.gcube.portlets.user.databasesmanager.server.util; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerDSL; import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerDataSpace; import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerFactory; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; /** * @author "Angela Italiano angela.italiano@isti.cnr.it" * */ public class SessionUtil { protected static Logger logger = Logger.getLogger(SessionUtil.class); public static ASLSession getSession(HttpSession httpSession) { String sessionID = httpSession.getId(); String user = (String) httpSession .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); if (user == null) { user = "loredana.liccardo"; httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user); ScopeProvider.instance.set("/gcube/devsec/devVRE"); ASLSession session = SessionManager.getInstance().getASLSession( sessionID, user); session.setScope("/gcube/devsec/devVRE"); return session; // return null; } else { logger.trace("user found in session " + user); } ASLSession session = SessionManager.getInstance().getASLSession( sessionID, user); return session; } public static StatisticalManagerFactory getFactory(HttpSession httpSession) { ASLSession session = getSession(httpSession); return getFactory(session); } public static StatisticalManagerFactory getFactory(ASLSession session) { ScopeProvider.instance.set(session.getScope()); return getFactory(session.getScope()); } public static StatisticalManagerFactory getFactory(String scope) { ScopeProvider.instance.set(scope.toString()); return StatisticalManagerDSL.createStateful() .withTimeout(5, TimeUnit.MINUTES).build(); // IS } public static StatisticalManagerDataSpace getDataSpaceService( HttpSession httpSession) { ASLSession session = getSession(httpSession); return getDataSpaceService(session); } public static StatisticalManagerDataSpace getDataSpaceService( ASLSession session) { ScopeProvider.instance.set(getScope(session)); return StatisticalManagerDSL.dataSpace() .withTimeout(5, TimeUnit.MINUTES).build(); } public static String getUsername(HttpSession httpSession) { ASLSession session = getSession(httpSession); return getUsername(session); } private static String getUsername(ASLSession session) { return session.getUsername(); } public static String getScope(HttpSession httpSession) { ASLSession session = getSession(httpSession); return getScope(session); } private static String getScope(ASLSession session) { return session.getScope().toString(); } }