3892: Workspace Enhancement: use a cache to the list of users during Workspace init

Task-Url: https://support.d4science.org/issues/3892

Updated GWTWorkspaceBuilder init

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@128472 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-05 11:00:04 +00:00
parent 4fa170fa62
commit ca0f8a1754
2 changed files with 84 additions and 73 deletions

View File

@ -1504,7 +1504,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.trace("Home Library User Manager getting list Gcube Group"); workspaceLogger.trace("Home Library User Manager getting list Gcube Group");
listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(hlUserManager.getGroups())); listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(hlUserManager.getGroups()));
workspaceLogger.debug("Returning list of contacts!"); workspaceLogger.debug("Returning list of contacts");
return listContactsModel; return listContactsModel;
} catch (Exception e) { } catch (Exception e) {

View File

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package org.gcube.portlets.user.workspace.server.util; package org.gcube.portlets.user.workspace.server.util;
@ -31,7 +31,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014 * @Feb 18, 2014
* *
@ -51,61 +51,61 @@ public class WsUtil {
public static final String URI_RESOLVER_SERVICE = "URI_RESOLVER_SERVICE"; public static final String URI_RESOLVER_SERVICE = "URI_RESOLVER_SERVICE";
public static final String PROPERTY_SPECIAL_FOLDER = "PROPERTY_SPECIAL_FOLDER"; public static final String PROPERTY_SPECIAL_FOLDER = "PROPERTY_SPECIAL_FOLDER";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //IN DEV public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //IN DEV
public static final String TEST_SCOPE = "/gcube/devsec"; public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "pasquale.pagano"; // public static final String TEST_USER = "pasquale.pagano";
// public static final String TEST_USER = "federico.defaveri"; // public static final String TEST_USER = "federico.defaveri";
// public static final String TEST_USER = "massimiliano.assante"; // public static final String TEST_USER = "massimiliano.assante";
// public static final String TEST_USER = "pasquale.pagano"; // public static final String TEST_USER = "pasquale.pagano";
// public static final String TEST_USER = "aureliano.gentile"; // public static final String TEST_USER = "aureliano.gentile";
// public static final String TEST_USER = "antonio.gioia"; // public static final String TEST_USER = "antonio.gioia";
//COMMENT THIS FOR RELEASE //COMMENT THIS FOR RELEASE
// public static final String TEST_USER = "francesco.mangiacrapa"; // public static final String TEST_USER = "francesco.mangiacrapa";
// public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa"; // public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
//UNCOMMENT THIS FOR RELEASE //UNCOMMENT THIS FOR RELEASE
public static String TEST_USER = "test.user"; public static String TEST_USER = "test.user";
public static String TEST_USER_FULL_NAME = "Test User"; public static String TEST_USER_FULL_NAME = "Test User";
protected static Logger logger = Logger.getLogger(WsUtil.class); protected static Logger logger = Logger.getLogger(WsUtil.class);
// public static boolean withoutPortal = false; // public static boolean withoutPortal = false;
/** /**
* *
* @return true if you're running into the portal, false if in development * @return true if you're running into the portal, false if in development
*/ */
public static boolean isWithinPortal() { public static boolean isWithinPortal() {
try { try {
UserLocalServiceUtil.getService(); UserLocalServiceUtil.getService();
return true; return true;
} }
catch (Exception ex) { catch (Exception ex) {
logger.trace("Development Mode ON"); logger.trace("Development Mode ON");
return false; return false;
} }
} }
public static ASLSession getAslSession(HttpSession httpSession) public static ASLSession getAslSession(HttpSession httpSession)
{ {
String sessionID = httpSession.getId(); String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session; ASLSession session;
if (user == null) { if (user == null) {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING /*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/ * COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER; user=TEST_USER;
if (!isWithinPortal()) { //DEV MODE if (!isWithinPortal()) { //DEV MODE
user = "francesco.mangiacrapa"; user = "francesco.mangiacrapa";
TEST_USER_FULL_NAME = "Francesco Mangiacrapa"; TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
} }
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:"); logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID); logger.warn("session id: "+sessionID);
logger.warn("TEST_USER: "+user); logger.warn("TEST_USER: "+user);
@ -113,27 +113,27 @@ public class WsUtil {
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE); logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user); session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE); session.setScope(TEST_SCOPE);
//MANDATORY FOR SOCIAL LIBRARY //MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar"); session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME); session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test"); session.setUserEmailAddress(user + "@mail.test");
//SET HTTP SESSION ATTRIBUTE //SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user); httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
// withoutPortal = true; // withoutPortal = true;
return session; return session;
} }
return SessionManager.getInstance().getASLSession(sessionID, user); return SessionManager.getInstance().getASLSession(sessionID, user);
} }
/** /**
* *
* @param httpSession * @param httpSession
* @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise * @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise
* @throws Exception * @throws Exception
@ -143,32 +143,32 @@ public class WsUtil {
//READING USERNAME FROM ASL SESSION //READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername(); String userUsername = getAslSession(httpSession).getUsername();
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0; boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
//TODO UNCOMMENT THIS FOR RELEASE //TODO UNCOMMENT THIS FOR RELEASE
logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser); logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
if(isTestUser){ if(isTestUser){
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER); logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
return true; //is TEST_USER, session is expired return true; //is TEST_USER, session is expired
} }
logger.trace("workspace session is valid! current username is: "+userUsername); logger.trace("workspace session is valid! current username is: "+userUsername);
return false; return false;
} }
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{ {
logger.trace("Get Workspace"); logger.trace("Get Workspace");
final ASLSession session = getAslSession(httpSession); final ASLSession session = getAslSession(httpSession);
logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername()); logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(session.getScope());
logger.trace("Scope provider instancied"); logger.trace("Scope provider instancied");
Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername());
/* /*
@ -193,7 +193,7 @@ public class WsUtil {
mcLoader.start(); mcLoader.start();
} }
if (session.getAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE) == null){ if (session.getAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE) == null){
logger.trace("Initializing the event collector"); logger.trace("Initializing the event collector");
@ -203,18 +203,19 @@ public class WsUtil {
session.setAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE, eventCollector); session.setAttribute(WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE, eventCollector);
} }
*/ */
/*
if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null) if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null)
{ {
logger.trace("Initializing the workspace area builder"); logger.trace("Initializing the workspace area builder");
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder(); GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
//ADDED 03/09/2013 //ADDED 03/09/2013
builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false)); builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false));
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder); session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
} }*/
return workspace; return workspace;
@ -248,14 +249,23 @@ public class WsUtil {
public static GWTWorkspaceBuilder getGWTWorkspaceBuilder(HttpSession httpSession) public static GWTWorkspaceBuilder getGWTWorkspaceBuilder(HttpSession httpSession)
{ {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
return (GWTWorkspaceBuilder) session.getAttribute(WsUtil.WORKSPACEBUILDER_ATTRIBUTE); GWTWorkspaceBuilder builder = (GWTWorkspaceBuilder) session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE);
if (builder == null){
logger.info("Initializing the workspace area builder");
builder = new GWTWorkspaceBuilder();
//ADDED 03/09/2013
builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false));
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
}
return builder;
} }
public static NotificationsManager getNotificationManager(ASLSession session) public static NotificationsManager getNotificationManager(ASLSession session)
{ {
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER); NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
if (notifMng == null) { if (notifMng == null) {
try{ try{
logger.trace("Create new NotificationsManager for user: "+session.getUsername()); logger.trace("Create new NotificationsManager for user: "+session.getUsername());
@ -266,62 +276,62 @@ public class WsUtil {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e); logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
} }
} }
return notifMng; return notifMng;
} }
public static NotificationsProducer getNotificationProducer(ASLSession session) public static NotificationsProducer getNotificationProducer(ASLSession session)
{ {
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER); NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) { if (notifProducer == null) {
logger.trace("Create new Notification Producer for user: "+session.getUsername()); logger.trace("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session); notifProducer = new NotificationsProducer(session);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer); session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
} }
return notifProducer; return notifProducer;
} }
public static String getUserId(HttpSession httpSession) { public static String getUserId(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
return session.getUsername(); return session.getUsername();
} }
public static boolean isVRE(ASLSession session){ public static boolean isVRE(ASLSession session){
String currentScope = session.getScopeName(); String currentScope = session.getScopeName();
int slashCount = StringUtils.countMatches(currentScope, "/"); int slashCount = StringUtils.countMatches(currentScope, "/");
if(slashCount < 3){ if(slashCount < 3){
logger.trace("currentScope is not VRE"); logger.trace("currentScope is not VRE");
return false; return false;
} }
logger.trace("currentScope is VRE"); logger.trace("currentScope is VRE");
return true; return true;
} }
public static ScopeUtilFilter getScopeUtilFilter(HttpSession httpSession){ public static ScopeUtilFilter getScopeUtilFilter(HttpSession httpSession){
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
ScopeUtilFilter scopeUtil = null; ScopeUtilFilter scopeUtil = null;
try{ try{
scopeUtil = (ScopeUtilFilter) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL); scopeUtil = (ScopeUtilFilter) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
if(scopeUtil==null){ if(scopeUtil==null){
scopeUtil = new ScopeUtilFilter(session.getScopeName(),true); scopeUtil = new ScopeUtilFilter(session.getScopeName(),true);
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("an error occurred in getscope filter "+e); logger.error("an error occurred in getscope filter "+e);
} }
return scopeUtil; return scopeUtil;
} }
@ -331,17 +341,17 @@ public class WsUtil {
* @return * @return
*/ */
public static UrlShortener getUrlShortener(HttpSession httpSession) { public static UrlShortener getUrlShortener(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
UrlShortener shortener = null; UrlShortener shortener = null;
try{ try{
shortener = (UrlShortener) session.getAttribute(WsUtil.URL_SHORTENER_SERVICE); shortener = (UrlShortener) session.getAttribute(WsUtil.URL_SHORTENER_SERVICE);
if(shortener==null){ if(shortener==null){
shortener = new UrlShortener(session.getScope().toString()); shortener = new UrlShortener(session.getScope().toString());
session.setAttribute(URL_SHORTENER_SERVICE, shortener); session.setAttribute(URL_SHORTENER_SERVICE, shortener);
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("an error occurred in instancing url shortener ",e); logger.error("an error occurred in instancing url shortener ",e);
} }
@ -355,18 +365,18 @@ public class WsUtil {
* @return * @return
*/ */
public static UriResolverReaderParameterForResolverIndex getUriResolver(HttpSession httpSession) { public static UriResolverReaderParameterForResolverIndex getUriResolver(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
UriResolverReaderParameterForResolverIndex uriResolver = null; UriResolverReaderParameterForResolverIndex uriResolver = null;
try{ try{
uriResolver = (UriResolverReaderParameterForResolverIndex) session.getAttribute(WsUtil.URI_RESOLVER_SERVICE); uriResolver = (UriResolverReaderParameterForResolverIndex) session.getAttribute(WsUtil.URI_RESOLVER_SERVICE);
if(uriResolver==null){ if(uriResolver==null){
uriResolver = new UriResolverReaderParameterForResolverIndex(session.getScope().toString(),RESOLVER_TYPE.SMP_ID); uriResolver = new UriResolverReaderParameterForResolverIndex(session.getScope().toString(),RESOLVER_TYPE.SMP_ID);
session.setAttribute(URI_RESOLVER_SERVICE, uriResolver); session.setAttribute(URI_RESOLVER_SERVICE, uriResolver);
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("an error occurred instancing URI Resolver ",e); logger.error("an error occurred instancing URI Resolver ",e);
} }
@ -380,16 +390,16 @@ public class WsUtil {
*/ */
public static PropertySpecialFolderReader getPropertySpecialFolderReader(HttpSession httpSession, String pathProperty) { public static PropertySpecialFolderReader getPropertySpecialFolderReader(HttpSession httpSession, String pathProperty) {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);
PropertySpecialFolderReader psFolderReader = null; PropertySpecialFolderReader psFolderReader = null;
try{ try{
psFolderReader = (PropertySpecialFolderReader) session.getAttribute(WsUtil.PROPERTY_SPECIAL_FOLDER); psFolderReader = (PropertySpecialFolderReader) session.getAttribute(WsUtil.PROPERTY_SPECIAL_FOLDER);
if(psFolderReader==null){ if(psFolderReader==null){
psFolderReader = new PropertySpecialFolderReader(pathProperty); psFolderReader = new PropertySpecialFolderReader(pathProperty);
session.setAttribute(PROPERTY_SPECIAL_FOLDER, psFolderReader); session.setAttribute(PROPERTY_SPECIAL_FOLDER, psFolderReader);
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("an error occurred instancing PropertySpecialFolderReader ",e); logger.error("an error occurred instancing PropertySpecialFolderReader ",e);
} }