- Class WsUtil replaced by SessionUtil in class GWTdbManagerServiceImpl.

- logger.error() added in class GWTdbManagerServiceImpl.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@99989 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-09-17 14:43:14 +00:00
parent 55549daaf3
commit c23955c7b1
3 changed files with 157 additions and 154 deletions

View File

@ -16,7 +16,6 @@ import javax.servlet.http.HttpSession;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import org.apache.regexp.RE;
import org.gcube.application.framework.core.session.ASLSession;
@ -54,16 +53,13 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
import org.gcube.portlets.user.databasesmanager.server.util.WsUtil;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.thoughtworks.xstream.XStream;
import org.apache.log4j.Logger;
//import org.apache.jcs.JCS;
//import org.apache.jcs.access.CacheAccess;
//import org.apache.jcs.utils.props.PropertyLoader;
public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
GWTdbManagerService {
@ -111,7 +107,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
logger.error("dbmanager-> Failed to get cache: " + e);
e.printStackTrace();
// e.printStackTrace();
throw e;
}
}
@ -134,14 +130,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// TODO: handle exception
logger.error("dbmanager-> " + e);
e.printStackTrace();
// e.printStackTrace();
}
}
private void initVariables() {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
// the result generated in the LoadTables method
@ -260,6 +256,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// TODO: handle exception
// e.printStackTrace();
// throw new Exception("Failed to load data. " + e);
logger.error("dbmanager-> " + e);
throw e;
}
// }
@ -351,8 +348,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
// e.printStackTrace();
// throw new Exception("Failed to load data " + );
logger.error("dbmanager-> " + e);
throw e;
}
@ -452,8 +450,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
// e.printStackTrace();
// throw new Exception("Failed to load data. " + e);
logger.error("dbmanager-> " + e);
throw e;
}
@ -554,6 +553,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// e.printStackTrace();
// throw new Exception("Failed to load data. " + e);
logger.error("dbmanager-> " + e);
throw e;
}
@ -803,6 +803,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
"javax.xml.ws.soap.SOAPFaultException: java.lang.IndexOutOfBoundsException")) {
e = new Exception("ServerException");
}
logger.error("dbmanager-> " + e);
throw e;
}
@ -1259,7 +1260,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// }
private synchronized List<Result> getSubmitQueryResult(String submitQueryUID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
@ -1272,7 +1273,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized List<Row> getSubmitQueryResultParsed(
String submitQueryUID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
@ -1287,7 +1288,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateSubmitQueryResultParsed(
String submitQueryUID, List<Row> data) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
@ -1300,7 +1301,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
private synchronized void removeResultParsed(String submitQueryUID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
@ -1316,7 +1317,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateSubmitQueryResultMap(String submitQueryUID,
List<Result> result) {
if (submitQueryUID != null) {
ASLSession session = WsUtil.getAslSession(this
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
@ -1326,7 +1327,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
private synchronized void removeResult(String submitQueryUID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
@ -1342,7 +1343,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateJobStatus(String jobID, String status) {
if (jobID != null) {
// add the job status
ASLSession session = WsUtil.getAslSession(this
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
.getAttribute("JobStatusList");
@ -1353,7 +1354,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// remove job with the related status
private synchronized void removeJobStatus(String jobID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
.getAttribute("JobStatusList");
@ -1366,7 +1367,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// get job status
private synchronized String getJobStatus(String jobID) {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
.getAttribute("JobStatusList");
@ -1378,7 +1379,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateJob(String jobID, String computationId) {
if (jobID != null) {
// add the computation in the map
ASLSession session = WsUtil.getAslSession(this
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> computationIDMap = (HashMap<String, String>) session
.getAttribute("ComputationIDList");
@ -1392,7 +1393,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (jobID != null) {
// System.out.println("remove jobID " + job);
// add the computation in the map
ASLSession session = WsUtil.getAslSession(this
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> computationIDMap = (HashMap<String, String>) session
.getAttribute("ComputationIDList");
@ -1409,7 +1410,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized boolean checkJob(String jobID) {
boolean isContained = false;
if (jobID != null) {
ASLSession session = WsUtil.getAslSession(this
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> computationIDMap = (HashMap<String, String>) session
.getAttribute("ComputationIDList");
@ -1471,6 +1472,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
logger.info("dbmanager-> startComputation: the job submit has failed!");
// e.printStackTrace();
logger.error("dbmanager-> " + e);
throw e;
}
}
@ -1811,6 +1813,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
employeeCache.remove(key);
} catch (Exception e) {
// TODO: handle exception
logger.error("dbmanager-> "+ e);
throw new Exception("Failure to clear the cache. " + e);
}
}

View File

@ -20,7 +20,7 @@ public class SessionUtil {
protected static Logger logger = Logger.getLogger(SessionUtil.class);
public static ASLSession getSession(HttpSession httpSession) {
public static ASLSession getAslSession(HttpSession httpSession) {
String sessionID = httpSession.getId();
String user = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
@ -28,7 +28,7 @@ public class SessionUtil {
if (user == null) {
// user = "loredana.liccardo";
user = "dbmanager";
user = "database.manager";
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
ScopeProvider.instance.set("/gcube/devsec/devVRE");
ASLSession session = SessionManager.getInstance().getASLSession(
@ -48,7 +48,7 @@ public class SessionUtil {
}
public static StatisticalManagerFactory getFactory(HttpSession httpSession) {
ASLSession session = getSession(httpSession);
ASLSession session = getAslSession(httpSession);
return getFactory(session);
}
@ -68,7 +68,7 @@ public class SessionUtil {
public static StatisticalManagerDataSpace getDataSpaceService(
HttpSession httpSession) {
ASLSession session = getSession(httpSession);
ASLSession session = getAslSession(httpSession);
return getDataSpaceService(session);
}
@ -81,7 +81,7 @@ public class SessionUtil {
}
public static String getUsername(HttpSession httpSession) {
ASLSession session = getSession(httpSession);
ASLSession session = getAslSession(httpSession);
return getUsername(session);
}
@ -90,7 +90,7 @@ public class SessionUtil {
}
public static String getScope(HttpSession httpSession) {
ASLSession session = getSession(httpSession);
ASLSession session = getAslSession(httpSession);
return getScope(session);
}

View File

@ -1,128 +1,128 @@
package org.gcube.portlets.user.databasesmanager.server.util;
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.applicationsupportlayer.social.ApplicationNotificationsManager;
//import org.gcube.applicationsupportlayer.social.NotificationsManager;
//import org.gcube.common.homelibrary.home.HomeLibrary;
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
//import org.gcube.common.homelibrary.home.workspace.Workspace;
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
//import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
//import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
//import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
//import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
//import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
//import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
//import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
*
*/
public class WsUtil {
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
// 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";
// public static final String NOTIFICATION_MANAGER = "NOTIFICATION_MANAGER";
// public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_PRODUCER";
// public static final String WS_RUN_IN_TEST_MODE = "WS_RUN_IN_TEST_MODE";
// public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL";
// public static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_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 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/devVRE";
// public static final String TEST_USER = "pasquale.pagano";
// public static final String TEST_USER = "federico.defaveri";
// public static final String TEST_USER = "massimiliano.assante";
// public static final String TEST_USER = "pasquale.pagano";
// public static final String TEST_USER = "aureliano.gentile";
// public static final String TEST_USER = "antonio.gioia";
//COMMENT THIS FOR RELEASE
// public static final String TEST_USER = "francesco.mangiacrapa";
// public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
//UNCOMMENT THIS FOR RELEASE
// public static final String TEST_USER = "test.user";
// public static final String TEST_USER_FULL_NAME = "Test User";
public static final String TEST_USER = "dbmanager";
public static final String TEST_USER_FULL_NAME = "dbmanager";
protected static Logger logger = Logger.getLogger(WsUtil.class);
public static boolean withoutPortal = false;
public static ASLSession getAslSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session;
if (user == null) {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
// user = "francesco.mangiacrapa";
// user = "valentina.marioli";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);
logger.warn("TEST_USER: "+user);
logger.warn("TEST_SCOPE: "+TEST_SCOPE);
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
//MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test");
//SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
withoutPortal = true;
return session;
}else if(user.compareToIgnoreCase(TEST_USER)==0){
withoutPortal = true;
//*** COMMENT THIS IN PRODUCTION ENVIROMENT
// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
//package org.gcube.portlets.user.databasesmanager.server.util;
//
//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.applicationsupportlayer.social.ApplicationNotificationsManager;
////import org.gcube.applicationsupportlayer.social.NotificationsManager;
////import org.gcube.common.homelibrary.home.HomeLibrary;
////import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
////import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
////import org.gcube.common.homelibrary.home.workspace.Workspace;
////import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
//import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
////import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
////import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
////import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
////import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
////import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
////import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
////import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
//
//
///**
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * @Feb 18, 2014
// *
// */
//public class WsUtil {
//
// public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
//// 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";
//// public static final String NOTIFICATION_MANAGER = "NOTIFICATION_MANAGER";
//// public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_PRODUCER";
//// public static final String WS_RUN_IN_TEST_MODE = "WS_RUN_IN_TEST_MODE";
//// public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL";
//// public static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_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 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/devVRE";
//
//
//// public static final String TEST_USER = "pasquale.pagano";
//// public static final String TEST_USER = "federico.defaveri";
//// public static final String TEST_USER = "massimiliano.assante";
//// public static final String TEST_USER = "pasquale.pagano";
//// public static final String TEST_USER = "aureliano.gentile";
//// public static final String TEST_USER = "antonio.gioia";
//
// //COMMENT THIS FOR RELEASE
//// public static final String TEST_USER = "francesco.mangiacrapa";
//// public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
//
// //UNCOMMENT THIS FOR RELEASE
//// public static final String TEST_USER = "test.user";
//// public static final String TEST_USER_FULL_NAME = "Test User";
//
// public static final String TEST_USER = "dbmanager";
// public static final String TEST_USER_FULL_NAME = "dbmanager";
//
//
// protected static Logger logger = Logger.getLogger(WsUtil.class);
//
// public static boolean withoutPortal = false;
//
// public static ASLSession getAslSession(HttpSession httpSession)
// {
// String sessionID = httpSession.getId();
// String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
// ASLSession session;
//
// if (user == null) {
//
// /*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
// * COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
// user=TEST_USER;
//
// //UNCOMMENT THIS IN DEVELOP ENVIROMENT
//// user = "francesco.mangiacrapa";
//// user = "valentina.marioli";
//
// logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
// logger.warn("session id: "+sessionID);
// logger.warn("TEST_USER: "+user);
// logger.warn("TEST_SCOPE: "+TEST_SCOPE);
// logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
// session = SessionManager.getInstance().getASLSession(sessionID, user);
// session.setScope(TEST_SCOPE);
//
//
// //MANDATORY FOR SOCIAL LIBRARY
// session.setUserAvatarId(user + "Avatar");
// session.setUserFullName(TEST_USER_FULL_NAME);
// session.setUserEmailAddress(user + "@mail.test");
//
// //SET HTTP SESSION ATTRIBUTE
// httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
//
// withoutPortal = true;
//*** END UNCOMMENT
}else{
withoutPortal = false;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
}
//
// return session;
//
// }else if(user.compareToIgnoreCase(TEST_USER)==0){
//
// withoutPortal = true;
//
////*** COMMENT THIS IN PRODUCTION ENVIROMENT
//// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
////
//// withoutPortal = true;
////*** END UNCOMMENT
// }else{
//
// withoutPortal = false;
// }
//
// return SessionManager.getInstance().getASLSession(sessionID, user);
// }
//
//}