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:
parent
fa1c741014
commit
bf34520449
|
@ -18,11 +18,12 @@ import org.apache.commons.fileupload.FileItemFactory;
|
|||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
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.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.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.TDGWTSessionExpiredException;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor;
|
||||
|
@ -65,19 +66,30 @@ public class CodelistMappingUploadServlet extends HttpServlet {
|
|||
return;
|
||||
}
|
||||
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) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
logger.error(
|
||||
"Error retrieving credentials:" + e.getLocalizedMessage(),
|
||||
e);
|
||||
throw new ServletException(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
CodelistMappingFileUploadSession codelistMappingFileUploadSession = new CodelistMappingFileUploadSession();
|
||||
// CodelistMappingMonitor codelistMappingMonitor=new
|
||||
// CodelistMappingMonitor();
|
||||
|
@ -87,14 +99,13 @@ public class CodelistMappingUploadServlet extends HttpServlet {
|
|||
codelistMappingFileUploadSession
|
||||
.setFileUploadState(FileUploadState.STARTED);
|
||||
// codelistMappingFileUploadSession.setCodelistMappingMonitor(codelistMappingMonitor);
|
||||
SessionUtil.setFileUploadMonitor(session, fileUploadMonitor);
|
||||
SessionUtil.setFileUploadMonitor(request, serviceCredentials, fileUploadMonitor);
|
||||
|
||||
try {
|
||||
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||
SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
|
||||
codelistMappingFileUploadSession);
|
||||
} catch (TDGWTSessionExpiredException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(),e);
|
||||
throw new ServletException(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
|
@ -118,18 +129,23 @@ public class CodelistMappingUploadServlet extends HttpServlet {
|
|||
}
|
||||
}
|
||||
} 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",
|
||||
FileUtil.exceptionDetailMessage(e));
|
||||
SessionUtil.setFileUploadMonitor(session, fum);
|
||||
SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
|
||||
codelistMappingFileUploadSession
|
||||
.setFileUploadState(FileUploadState.FAILED);
|
||||
try {
|
||||
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||
SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
|
||||
codelistMappingFileUploadSession);
|
||||
} catch (TDGWTSessionExpiredException e1) {
|
||||
logger.error(e1.getLocalizedMessage());
|
||||
e1.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
logger.error(e1.getLocalizedMessage(),e1);
|
||||
throw new ServletException(e1.getLocalizedMessage());
|
||||
}
|
||||
logger.error("Error processing request in upload servlet", e);
|
||||
|
@ -139,20 +155,25 @@ public class CodelistMappingUploadServlet extends HttpServlet {
|
|||
}
|
||||
|
||||
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(
|
||||
"An error occured elaborating the HTTP request: No file found",
|
||||
"Upload request without file");
|
||||
SessionUtil.setFileUploadMonitor(session, fum);
|
||||
SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
|
||||
|
||||
codelistMappingFileUploadSession
|
||||
.setFileUploadState(FileUploadState.FAILED);
|
||||
try {
|
||||
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||
SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
|
||||
codelistMappingFileUploadSession);
|
||||
} catch (TDGWTSessionExpiredException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(),e);
|
||||
throw new ServletException(e.getLocalizedMessage());
|
||||
}
|
||||
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(),
|
||||
contentType);
|
||||
} 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",
|
||||
FileUtil.exceptionDetailMessage(e));
|
||||
SessionUtil.setFileUploadMonitor(session, fum);
|
||||
SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
|
||||
|
||||
codelistMappingFileUploadSession
|
||||
.setFileUploadState(FileUploadState.FAILED);
|
||||
try {
|
||||
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||
SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
|
||||
codelistMappingFileUploadSession);
|
||||
} catch (TDGWTSessionExpiredException e1) {
|
||||
logger.error(e1.getLocalizedMessage());
|
||||
e1.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
logger.error(e1.getLocalizedMessage(),e1);
|
||||
throw new ServletException(e1.getLocalizedMessage());
|
||||
}
|
||||
logger.error("Error elaborating the stream", e);
|
||||
|
@ -195,16 +221,21 @@ public class CodelistMappingUploadServlet extends HttpServlet {
|
|||
uploadItem.delete();
|
||||
|
||||
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);
|
||||
SessionUtil.setFileUploadMonitor(session, fum);
|
||||
SessionUtil.setFileUploadMonitor(request, serviceCredentials, fum);
|
||||
|
||||
try {
|
||||
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||
SessionUtil.setCodelistMappingFileUploadSession(request, serviceCredentials,
|
||||
codelistMappingFileUploadSession);
|
||||
} catch (TDGWTSessionExpiredException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(),e);
|
||||
throw new ServletException(e.getLocalizedMessage());
|
||||
}
|
||||
response.getWriter().write("OK");
|
||||
|
|
|
@ -12,6 +12,9 @@ package org.gcube.portlets.user.td.gwtservice.shared;
|
|||
public class Constants {
|
||||
public static final boolean DEBUG_MODE = 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";
|
||||
|
|
Loading…
Reference in New Issue