Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@95711 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-05-15 10:56:32 +00:00
parent f4141e81fa
commit 71cd544fdf
3 changed files with 63 additions and 27 deletions

View File

@ -22,6 +22,7 @@ import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener;
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -69,7 +70,13 @@ public class LocalUploadServlet extends HttpServlet {
fileUploadSession.setCsvImportMonitor(csvImportMonitor); fileUploadSession.setCsvImportMonitor(csvImportMonitor);
fileUploadSession.setFileUploadMonitor(fileUploadMonitor); fileUploadSession.setFileUploadMonitor(fileUploadMonitor);
SessionUtil.setFileUploadSession(session,fileUploadSession); try {
SessionUtil.setFileUploadSession(session,fileUploadSession);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage());
e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage());
}
FileItemFactory factory = new DiskFileItemFactory(); FileItemFactory factory = new DiskFileItemFactory();
@ -93,7 +100,13 @@ public class LocalUploadServlet extends HttpServlet {
} catch (FileUploadException e) { } catch (FileUploadException e) {
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e)); fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e));
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
SessionUtil.setFileUploadSession(session, fileUploadSession); try {
SessionUtil.setFileUploadSession(session, fileUploadSession);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage());
e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage());
}
logger.error("Error processing request in upload servlet", e); logger.error("Error processing request in upload servlet", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error during request processing: "+e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error during request processing: "+e.getMessage());
return; return;
@ -102,7 +115,13 @@ public class LocalUploadServlet extends HttpServlet {
if (uploadItem == null) { if (uploadItem == null) {
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file"); fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file");
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
SessionUtil.setFileUploadSession(session, fileUploadSession); try {
SessionUtil.setFileUploadSession(session, fileUploadSession);
} catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage());
}
logger.error("Error processing request in upload servlet: No file to upload"); logger.error("Error processing request in upload servlet: No file to upload");
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file to upload"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file to upload");
return; return;
@ -118,7 +137,13 @@ public class LocalUploadServlet extends HttpServlet {
} catch (Exception e) { } catch (Exception e) {
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e)); fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
SessionUtil.setFileUploadSession(session, fileUploadSession); try {
SessionUtil.setFileUploadSession(session, fileUploadSession);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage());
e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage());
}
logger.error("Error elaborating the stream", e); logger.error("Error elaborating the stream", e);
uploadItem.delete(); uploadItem.delete();
response.getWriter().write("ERROR-"+e.getMessage()); response.getWriter().write("ERROR-"+e.getMessage());
@ -129,7 +154,13 @@ public class LocalUploadServlet extends HttpServlet {
logger.trace("changing state"); logger.trace("changing state");
fileUploadSession.getFileUploadMonitor().setState(FileUploadState.COMPLETED); fileUploadSession.getFileUploadMonitor().setState(FileUploadState.COMPLETED);
SessionUtil.setFileUploadSession(session, fileUploadSession); try {
SessionUtil.setFileUploadSession(session, fileUploadSession);
} catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage());
}
response.getWriter().write("OK"); response.getWriter().write("OK");
} }

View File

@ -16,9 +16,9 @@ import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager; import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession;
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSessionMonitor; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSessionMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession;
@ -137,12 +137,14 @@ public class SessionUtil {
protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class); protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getAslSession(HttpSession httpSession) { public static ASLSession getAslSession(HttpSession httpSession) throws TDGWTServiceException {
String username = (String) httpSession String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession session; ASLSession session;
if (username == null) { if (username == null) {
logger.warn("no user found in session, using test one"); logger.warn("no user found in session, using test one");
throw new TDGWTServiceException("Session Expired!");
/*
username = Constants.DEFAULT_USER; username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE; String scope = Constants.DEFAULT_SCOPE;
@ -150,7 +152,7 @@ public class SessionUtil {
session = SessionManager.getInstance().getASLSession( session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
session.setScope(scope); session.setScope(scope);
*/
} else { } else {
session = SessionManager.getInstance().getASLSession( session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
@ -164,7 +166,7 @@ public class SessionUtil {
} }
public static void setTDOpenSession(HttpSession httpSession, TDOpenSession s) { public static void setTDOpenSession(HttpSession httpSession, TDOpenSession s) throws TDGWTServiceException {
TDOpenSession session = (TDOpenSession) httpSession TDOpenSession session = (TDOpenSession) httpSession
.getAttribute(TDOPEN_SESSION); .getAttribute(TDOPEN_SESSION);
@ -185,7 +187,7 @@ public class SessionUtil {
} }
public static void setTabularResources(HttpSession httpSession, public static void setTabularResources(HttpSession httpSession,
List<TabularResource> trs) { List<TabularResource> trs) throws TDGWTServiceException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<TabularResource> tabularResources = (List<TabularResource>) httpSession List<TabularResource> tabularResources = (List<TabularResource>) httpSession
@ -205,7 +207,7 @@ public class SessionUtil {
return id; return id;
} }
public static void setTRId(HttpSession httpSession, TRId trId) { public static void setTRId(HttpSession httpSession, TRId trId) throws TDGWTServiceException {
TRId id = (TRId) httpSession.getAttribute(CURRENT_TR_ID); TRId id = (TRId) httpSession.getAttribute(CURRENT_TR_ID);
if (id != null) if (id != null)
httpSession.removeAttribute(CURRENT_TR_ID); httpSession.removeAttribute(CURRENT_TR_ID);
@ -224,7 +226,7 @@ public class SessionUtil {
} }
public static void setTabResource(HttpSession httpSession, public static void setTabResource(HttpSession httpSession,
TabResource tabResource) { TabResource tabResource) throws TDGWTServiceException {
TabResource t = (TabResource) httpSession TabResource t = (TabResource) httpSession
.getAttribute(CURRENT_TABULAR_RESOURCE); .getAttribute(CURRENT_TABULAR_RESOURCE);
if (t != null) if (t != null)
@ -244,7 +246,7 @@ public class SessionUtil {
} }
public static void setSDMXImportTabResource(HttpSession httpSession, public static void setSDMXImportTabResource(HttpSession httpSession,
TabResource tabResource) { TabResource tabResource) throws TDGWTServiceException {
TabResource t = (TabResource) httpSession TabResource t = (TabResource) httpSession
.getAttribute(SDMX_IMPORT_TABULAR_RESOURCE); .getAttribute(SDMX_IMPORT_TABULAR_RESOURCE);
if (t != null) if (t != null)
@ -265,7 +267,7 @@ public class SessionUtil {
} }
public static void setCSVImportTabResource(HttpSession httpSession, public static void setCSVImportTabResource(HttpSession httpSession,
TabResource tabResource) { TabResource tabResource) throws TDGWTServiceException {
TabResource t = (TabResource) httpSession TabResource t = (TabResource) httpSession
.getAttribute(CSV_IMPORT_TABULAR_RESOURCE); .getAttribute(CSV_IMPORT_TABULAR_RESOURCE);
if (t != null) if (t != null)
@ -278,7 +280,7 @@ public class SessionUtil {
// // // //
public static void setSDMXImportSession(HttpSession httpSession, public static void setSDMXImportSession(HttpSession httpSession,
SDMXImportSession s) { SDMXImportSession s) throws TDGWTServiceException {
SDMXImportSession session = (SDMXImportSession) httpSession SDMXImportSession session = (SDMXImportSession) httpSession
.getAttribute(SDMX_IMPORT_SESSION); .getAttribute(SDMX_IMPORT_SESSION);
@ -299,7 +301,7 @@ public class SessionUtil {
} }
public static void setCSVImportSession(HttpSession httpSession, public static void setCSVImportSession(HttpSession httpSession,
CSVImportSession s) { CSVImportSession s) throws TDGWTServiceException {
CSVImportSession session = (CSVImportSession) httpSession CSVImportSession session = (CSVImportSession) httpSession
.getAttribute(CSV_IMPORT_SESSION); .getAttribute(CSV_IMPORT_SESSION);
@ -320,7 +322,7 @@ public class SessionUtil {
} }
public static void setCSVExportSession(HttpSession httpSession, public static void setCSVExportSession(HttpSession httpSession,
CSVExportSession s) { CSVExportSession s) throws TDGWTServiceException {
CSVExportSession session = (CSVExportSession) httpSession CSVExportSession session = (CSVExportSession) httpSession
.getAttribute(CSV_EXPORT_SESSION); .getAttribute(CSV_EXPORT_SESSION);
@ -341,7 +343,7 @@ public class SessionUtil {
} }
public static void setSDMXExportSession(HttpSession httpSession, public static void setSDMXExportSession(HttpSession httpSession,
SDMXExportSession s) { SDMXExportSession s) throws TDGWTServiceException {
SDMXExportSession session = (SDMXExportSession) httpSession SDMXExportSession session = (SDMXExportSession) httpSession
.getAttribute(SDMX_EXPORT_SESSION); .getAttribute(SDMX_EXPORT_SESSION);
@ -362,7 +364,7 @@ public class SessionUtil {
} }
public static void setFileUploadSession(HttpSession httpSession, public static void setFileUploadSession(HttpSession httpSession,
FileUploadSession s) { FileUploadSession s) throws TDGWTServiceException {
FileUploadSession session = (FileUploadSession) httpSession FileUploadSession session = (FileUploadSession) httpSession
.getAttribute(CSV_IMPORT_FILE_UPLOAD_SESSION); .getAttribute(CSV_IMPORT_FILE_UPLOAD_SESSION);
@ -410,7 +412,7 @@ public class SessionUtil {
} }
public static void setSDMXRegistrySource(HttpSession httpSession, public static void setSDMXRegistrySource(HttpSession httpSession,
SDMXRegistrySource sdmxRegistrySource) { SDMXRegistrySource sdmxRegistrySource) throws TDGWTServiceException {
SDMXRegistrySource source = (SDMXRegistrySource) httpSession SDMXRegistrySource source = (SDMXRegistrySource) httpSession
.getAttribute(SDMX_REGISTRY_SOURCE); .getAttribute(SDMX_REGISTRY_SOURCE);

View File

@ -406,7 +406,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
TabResource currentTR = SessionUtil.getTabResource(session); TabResource currentTR = SessionUtil.getTabResource(session);
if (currentTR == null) { if (currentTR == null) {
logger.error("CURRENT_TABULAR_RESOURCE is null"); logger.error("CURRENT_TABULAR_RESOURCE is null");
@ -526,7 +527,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername())); aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
@ -2169,7 +2171,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername())); aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
@ -6063,7 +6065,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
} }
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -6073,7 +6076,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("discard(): " + trId); logger.debug("discard(): " + trId);
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
@ -6134,7 +6137,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("rollBack(): " + rollBackSession); logger.debug("rollBack(): " + rollBackSession);
SessionUtil.setRollBackSession(session, rollBackSession); SessionUtil.setRollBackSession(session, rollBackSession);
@ -6275,7 +6278,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("GetTableValidationsMetadata on " + trId.toString()); logger.debug("GetTableValidationsMetadata on " + trId.toString());
AuthorizationProvider.instance.set(new AuthorizationToken( AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername())); aslSession.getUsername()));