refs 6548: TDM - Migrate TabMan to new PortalContext

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

Updated CodelistMappingUploadServlet

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@141718 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-01-23 18:02:20 +00:00
parent fa1c741014
commit bf34520449
2 changed files with 72 additions and 38 deletions

View File

@ -18,11 +18,12 @@ import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession;
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener; import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener;
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.server.util.ServiceCredentials;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor;
@ -65,19 +66,30 @@ public class CodelistMappingUploadServlet extends HttpServlet {
return; return;
} }
logger.info("Codelist Mapping session id: " + session.getId()); logger.info("Codelist Mapping session id: " + session.getId());
try {
ASLSession aslSession = SessionUtil.getAslSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ScopeProvider.instance.set(aslSession.getScope().toString());
ServiceCredentials serviceCredentials;
try {
String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
// String currUserId = request
// .getParameter(Constants.CURR_USER_ID);
// serviceCredentials = SessionUtil.getServiceCredentials(request,
// scopeGroupId, currUserId);
serviceCredentials = SessionUtil.getServiceCredentials(request,
scopeGroupId);
ScopeProvider.instance.set(serviceCredentials.getScope());
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage()); logger.error(
e.printStackTrace(); "Error retrieving credentials:" + e.getLocalizedMessage(),
e);
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }
CodelistMappingFileUploadSession codelistMappingFileUploadSession = new CodelistMappingFileUploadSession(); CodelistMappingFileUploadSession codelistMappingFileUploadSession = new CodelistMappingFileUploadSession();
// CodelistMappingMonitor codelistMappingMonitor=new // CodelistMappingMonitor codelistMappingMonitor=new
// CodelistMappingMonitor(); // CodelistMappingMonitor();
@ -87,14 +99,13 @@ public class CodelistMappingUploadServlet extends HttpServlet {
codelistMappingFileUploadSession codelistMappingFileUploadSession
.setFileUploadState(FileUploadState.STARTED); .setFileUploadState(FileUploadState.STARTED);
// codelistMappingFileUploadSession.setCodelistMappingMonitor(codelistMappingMonitor); // codelistMappingFileUploadSession.setCodelistMappingMonitor(codelistMappingMonitor);
SessionUtil.setFileUploadMonitor(session, fileUploadMonitor); SessionUtil.setFileUploadMonitor(request, serviceCredentials, fileUploadMonitor);
try { try {
SessionUtil.setCodelistMappingFileUploadSession(session, SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
codelistMappingFileUploadSession); codelistMappingFileUploadSession);
} catch (TDGWTSessionExpiredException e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }
@ -118,18 +129,23 @@ public class CodelistMappingUploadServlet extends HttpServlet {
} }
} }
} catch (FileUploadException e) { } catch (FileUploadException e) {
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum=null;
try {
fum = SessionUtil.getFileUploadMonitor(request, serviceCredentials);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage(),e1);
throw new ServletException(e1.getLocalizedMessage());
}
fum.setFailed("An error occured elaborating the HTTP request", fum.setFailed("An error occured elaborating the HTTP request",
FileUtil.exceptionDetailMessage(e)); FileUtil.exceptionDetailMessage(e));
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
codelistMappingFileUploadSession codelistMappingFileUploadSession
.setFileUploadState(FileUploadState.FAILED); .setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodelistMappingFileUploadSession(session, SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
codelistMappingFileUploadSession); codelistMappingFileUploadSession);
} catch (TDGWTSessionExpiredException e1) { } catch (Exception e1) {
logger.error(e1.getLocalizedMessage()); logger.error(e1.getLocalizedMessage(),e1);
e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage()); throw new ServletException(e1.getLocalizedMessage());
} }
logger.error("Error processing request in upload servlet", e); logger.error("Error processing request in upload servlet", e);
@ -139,20 +155,25 @@ public class CodelistMappingUploadServlet extends HttpServlet {
} }
if (uploadItem == null) { if (uploadItem == null) {
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum=null;
try {
fum = SessionUtil.getFileUploadMonitor(request, serviceCredentials);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage(),e1);
throw new ServletException(e1.getLocalizedMessage());
}
fum.setFailed( fum.setFailed(
"An error occured elaborating the HTTP request: No file found", "An error occured elaborating the HTTP request: No file found",
"Upload request without file"); "Upload request without file");
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
codelistMappingFileUploadSession codelistMappingFileUploadSession
.setFileUploadState(FileUploadState.FAILED); .setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodelistMappingFileUploadSession(session, SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
codelistMappingFileUploadSession); codelistMappingFileUploadSession);
} catch (TDGWTSessionExpiredException e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); 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");
@ -171,19 +192,24 @@ public class CodelistMappingUploadServlet extends HttpServlet {
uploadItem.getInputStream(), uploadItem.getName(), uploadItem.getInputStream(), uploadItem.getName(),
contentType); contentType);
} catch (Exception e) { } catch (Exception e) {
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum=null;
try {
fum = SessionUtil.getFileUploadMonitor(request, serviceCredentials);
} catch (TDGWTServiceException e1) {
logger.error(e1.getLocalizedMessage(),e1);
throw new ServletException(e1.getLocalizedMessage());
}
fum.setFailed("An error occured elaborating the file", fum.setFailed("An error occured elaborating the file",
FileUtil.exceptionDetailMessage(e)); FileUtil.exceptionDetailMessage(e));
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
codelistMappingFileUploadSession codelistMappingFileUploadSession
.setFileUploadState(FileUploadState.FAILED); .setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodelistMappingFileUploadSession(session, SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
codelistMappingFileUploadSession); codelistMappingFileUploadSession);
} catch (TDGWTSessionExpiredException e1) { } catch (Exception e1) {
logger.error(e1.getLocalizedMessage()); logger.error(e1.getLocalizedMessage(),e1);
e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage()); throw new ServletException(e1.getLocalizedMessage());
} }
logger.error("Error elaborating the stream", e); logger.error("Error elaborating the stream", e);
@ -195,16 +221,21 @@ public class CodelistMappingUploadServlet extends HttpServlet {
uploadItem.delete(); uploadItem.delete();
logger.trace("changing state"); logger.trace("changing state");
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum=null;
try {
fum = SessionUtil.getFileUploadMonitor(request, serviceCredentials);
} catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage(),e);
throw new ServletException(e.getLocalizedMessage());
}
fum.setState(FileUploadState.COMPLETED); fum.setState(FileUploadState.COMPLETED);
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
try { try {
SessionUtil.setCodelistMappingFileUploadSession(session, SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
codelistMappingFileUploadSession); codelistMappingFileUploadSession);
} catch (TDGWTSessionExpiredException e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }
response.getWriter().write("OK"); response.getWriter().write("OK");

View File

@ -12,6 +12,9 @@ package org.gcube.portlets.user.td.gwtservice.shared;
public class Constants { public class Constants {
public static final boolean DEBUG_MODE = true; public static final boolean DEBUG_MODE = true;
public static final boolean TEST_ENABLE = true; public static final boolean TEST_ENABLE = true;
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
//public static final String CURR_USER_ID = "CURR_USER_ID";
public static final String DEFAULT_USER = "giancarlo.panichi"; public static final String DEFAULT_USER = "giancarlo.panichi";