Fixed bug on currUserId. See #6275

Not it is passed as parameter

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@141320 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-12-21 13:55:54 +00:00
parent 163bb37c45
commit 3e267e603b
7 changed files with 127 additions and 176 deletions

View File

@ -944,7 +944,8 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
try { try {
// Add currentContextId parameter // Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId(); String currentContextId = GCubeClientContext.getCurrentContextId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&viewContent=true&"+ConstantsExplorer.CONTEXT_ID+"="+currentContextId; String currentUserId = GCubeClientContext.getCurrentUserId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&viewContent=true&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId+"&"+ConstantsExplorer.CURRENT_USER_ID+"="+currentUserId;
new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_blank", downloadHandlerCallback); new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_blank", downloadHandlerCallback);
} catch (Exception e) { } catch (Exception e) {
@ -966,7 +967,8 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
try { try {
// Add currentContextId parameter // Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId(); String currentContextId = GCubeClientContext.getCurrentContextId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&"+ConstantsExplorer.CONTEXT_ID+"="+currentContextId; String currentUserId = GCubeClientContext.getCurrentUserId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId+"&"+ConstantsExplorer.CURRENT_USER_ID+"="+currentUserId;
new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_self", downloadHandlerCallback); new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_self", downloadHandlerCallback);
} catch (Exception e) { } catch (Exception e) {
explorerPanel.getAsycTreePanel().unmask(); explorerPanel.getAsycTreePanel().unmask();

View File

@ -229,7 +229,8 @@ public static enum WS_UPLOAD_TYPE {File, Archive};
//SERLVET PARAMETERS //SERLVET PARAMETERS
public static final String ERROR_ITEM_DOES_NOT_EXIST = "Item does not exist. It may have been deleted by another user"; public static final String ERROR_ITEM_DOES_NOT_EXIST = "Item does not exist. It may have been deleted by another user";
public static final String VALIDATEITEM = "validateitem"; public static final String VALIDATEITEM = "validateitem";
public static final String CONTEXT_ID = "contextID"; public static final String CURRENT_CONTEXT_ID = "contextID";
public static final String CURRENT_USER_ID = "currUserId";
public static final String REDIRECTONERROR = "redirectonerror"; public static final String REDIRECTONERROR = "redirectonerror";
//UPLOAD SERVLET PARAMETERS //UPLOAD SERVLET PARAMETERS

View File

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package org.gcube.portlets.user.workspace.server; package org.gcube.portlets.user.workspace.server;
@ -24,7 +24,7 @@ import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 1, 2013 * @Jul 1, 2013
* *
@ -47,59 +47,27 @@ public class DownloadPublicLinkServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String smp = req.getParameter("smp"); String smp = req.getParameter("smp");
boolean viewContent = (req.getParameter("viewContent")==null)?false:req.getParameter("viewContent").equals("true"); boolean viewContent = req.getParameter("viewContent")==null?false:req.getParameter("viewContent").equals("true");
logger.trace("Input Params [smp: "+smp + ", viewContent: "+viewContent+"]"); logger.trace("Input Params [smp: "+smp + ", viewContent: "+viewContent+"]");
if(smp==null || smp.isEmpty()){ if(smp==null || smp.isEmpty()){
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null"); sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null");
return; return;
} }
logger.trace("PUBLIC FILE DOWNLOAD REQUEST "+smp); logger.trace("PUBLIC FILE DOWNLOAD REQUEST "+smp);
//COMMENTED 26/03/2013
// String itemName = MimeTypeUtil.getNameWithExtension(item.getName(), mimeType);
// String contentDisposition = (viewContent)?"inline":"attachment";
// //COMMENTED 26/03/2013
//// resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
// resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + item.getName() + "\"" );
//
// resp.setContentType(mimeType);
//
// resp.setContentLength((int) externalFile.getLength());
//
//
// //MODIFIED 22-05-2013 CLOSE STREAM
//// IOUtils.copy(externalFile.getData(), resp.getOutputStream());
// is = externalFile.getData();
// out = resp.getOutputStream();
// IOUtils.copy(is, out);
//
// is.close();
// out.close();
} }
// protected void handleError(boolean urlRedirectOnError, HttpServletRequest req, HttpServletResponse resp, String itemId, String message) throws IOException{
//
// logger.warn("Handle error occurred: "+message);
// if(urlRedirectOnError){
// urlRedirect(req, resp, itemId);
// }else
// sendError(resp,message);
//
// }
protected void sendError(HttpServletResponse response, String message) throws IOException protected void sendError(HttpServletResponse response, String message) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message); HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString()); response.getWriter().write(resultMessage.toString());
response.flushBuffer(); response.flushBuffer();
} }
public static String getRequestURL(HttpServletRequest req) { public static String getRequestURL(HttpServletRequest req) {
String scheme = req.getScheme(); // http String scheme = req.getScheme(); // http
@ -114,86 +82,41 @@ public class DownloadPublicLinkServlet extends HttpServlet{
StringBuffer url = new StringBuffer(); StringBuffer url = new StringBuffer();
url.append(scheme).append("://").append(serverName); url.append(scheme).append("://").append(serverName);
if ((serverPort != 80) && (serverPort != 443)) { if (serverPort != 80 && serverPort != 443) {
url.append(":").append(serverPort); url.append(":").append(serverPort);
} }
logger.trace("server: "+url); logger.trace("server: "+url);
logger.trace("contextPath: "+contextPath); logger.trace("contextPath: "+contextPath);
// logger.trace("servletPath: "+servletPath);
// url.append(contextPath).append(servletPath);
url.append(contextPath);
// if (pathInfo != null) { url.append(contextPath);
// url.append(pathInfo);
// }
// if (queryString != null) {
// url.append("?").append(queryString);
// }
PortalUrlGroupGatewayProperty p = new PortalUrlGroupGatewayProperty(); PortalUrlGroupGatewayProperty p = new PortalUrlGroupGatewayProperty();
int lenght = p.getPath().length(); int lenght = p.getPath().length();
String groupgatewaypath = "/"; String groupgatewaypath = "/";
if(lenght>1){ if(lenght>1){
String lastChar = p.getPath().substring(lenght-1, lenght-1); String lastChar = p.getPath().substring(lenght-1, lenght-1);
groupgatewaypath+= lastChar.compareTo("/")!=0?p.getPath()+"/":p.getPath(); groupgatewaypath+= lastChar.compareTo("/")!=0?p.getPath()+"/":p.getPath();
} }
url.append(groupgatewaypath); url.append(groupgatewaypath);
return url.toString(); return url.toString();
} }
public static void main(String[] args) { public static void main(String[] args) {
InputStream is = null; InputStream is = null;
logger.trace("start"); logger.trace("start");
// is = GCUBEStorage.getRemoteFile("/Home/test.user/Workspace3d660604-03ef-49eb-89c3-4c73f8a47914");
try{ try{
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome("francesco.mangiacrapa").getWorkspace(); Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome("francesco.mangiacrapa").getWorkspace();
//
// ExternalFile f = (ExternalFile) ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
WorkspaceItem wsItem = ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b"); WorkspaceItem wsItem = ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
logger.trace("metadata info recovered from HL: [ID: "+wsItem.getId() +", name: "+wsItem.getName()+"]"); logger.trace("metadata info recovered from HL: [ID: "+wsItem.getId() +", name: "+wsItem.getName()+"]");
FileOutputStream out = new FileOutputStream(new File("/tmp/bla")); FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
// byte[] buffer = new byte[1024];
// int len;
// while ((len = is.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
logger.trace("cast as external file"); logger.trace("cast as external file");
ExternalFile f = (ExternalFile) wsItem; ExternalFile f = (ExternalFile) wsItem;
is = f.getData(); is = f.getData();
IOUtils.copy(is, out); IOUtils.copy(is, out);
is.close(); is.close();
out.close(); out.close();
// logger.trace("Sleeping");
// Thread.sleep(20000);
// logger.trace("Alive");
logger.trace("end"); logger.trace("end");
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -35,16 +35,19 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries;
import org.gcube.common.homelibrary.util.Extensions; import org.gcube.common.homelibrary.util.Extensions;
import org.gcube.common.homelibrary.util.MimeTypeUtil; import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.homelibrary.util.zip.ZipUtil; import org.gcube.common.homelibrary.util.zip.ZipUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty; import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
/** /**
* The Class DownloadServlet.
*
* @author Federico De Faveri defaveri@isti.cnr.it * @author Federico De Faveri defaveri@isti.cnr.it
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 21, 2016
*/ */
public class DownloadServlet extends HttpServlet{ public class DownloadServlet extends HttpServlet{
@ -61,13 +64,17 @@ public class DownloadServlet extends HttpServlet{
logger.trace("Workspace DownloadServlet ready."); logger.trace("Workspace DownloadServlet ready.");
} }
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String itemId = req.getParameter("id"); String itemId = req.getParameter("id");
boolean viewContent = req.getParameter("viewContent")==null?false:req.getParameter("viewContent").equals("true"); boolean viewContent = req.getParameter("viewContent")==null?false:req.getParameter("viewContent").equals("true");
boolean isValidItem = req.getParameter(ConstantsExplorer.VALIDATEITEM)==null?false:req.getParameter(ConstantsExplorer.VALIDATEITEM).equals("true"); boolean isValidItem = req.getParameter(ConstantsExplorer.VALIDATEITEM)==null?false:req.getParameter(ConstantsExplorer.VALIDATEITEM).equals("true");
boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true"); boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true");
String contextID = req.getParameter(ConstantsExplorer.CONTEXT_ID); String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID);
String userID = req.getParameter(ConstantsExplorer.CURRENT_USER_ID);
logger.debug("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+", contextID: "+contextID+"]"); logger.debug("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+", contextID: "+contextID+"]");
if(itemId==null || itemId.isEmpty()){ if(itemId==null || itemId.isEmpty()){
@ -82,9 +89,7 @@ public class DownloadServlet extends HttpServlet{
if(WsUtil.isSessionExpired(req)) if(WsUtil.isSessionExpired(req))
throw new SessionExpiredException(); throw new SessionExpiredException();
String currentScope= PortalContext.getConfiguration().getCurrentScope(contextID); wa = WsUtil.getWorkspace(req, contextID, userID);
logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope);
wa = WsUtil.getWorkspace(req, currentScope);
} catch (Exception e) { } catch (Exception e) {
if (e instanceof SessionExpiredException){ if (e instanceof SessionExpiredException){
@ -423,10 +428,11 @@ public class DownloadServlet extends HttpServlet{
} }
/** /**
* Method to manage HttpServletResponse content length also to big data * Method to manage HttpServletResponse content length also to big data.
* @param resp *
* @param length * @param resp the resp
* @return * @param length the length
* @return the http servlet response
*/ */
protected HttpServletResponse setContentLength(HttpServletResponse resp, long length){ protected HttpServletResponse setContentLength(HttpServletResponse resp, long length){
try{ try{
@ -440,6 +446,16 @@ public class DownloadServlet extends HttpServlet{
return resp; return resp;
} }
/**
* Handle error.
*
* @param urlRedirectOnError the url redirect on error
* @param req the req
* @param resp the resp
* @param itemId the item id
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void handleError(boolean urlRedirectOnError, HttpServletRequest req, HttpServletResponse resp, String itemId, String message) throws IOException{ protected void handleError(boolean urlRedirectOnError, HttpServletRequest req, HttpServletResponse resp, String itemId, String message) throws IOException{
logger.warn("Handle error occurred: "+message); logger.warn("Handle error occurred: "+message);
@ -451,6 +467,13 @@ public class DownloadServlet extends HttpServlet{
} }
/**
* Send error.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendError(HttpServletResponse response, String message) throws IOException protected void sendError(HttpServletResponse response, String message) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@ -465,6 +488,14 @@ public class DownloadServlet extends HttpServlet{
} }
/**
* Send error for status.
*
* @param response the response
* @param message the message
* @param status the status
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendErrorForStatus(HttpServletResponse response, String message, int status) throws IOException protected void sendErrorForStatus(HttpServletResponse response, String message, int status) throws IOException
{ {
response.setStatus(status); response.setStatus(status);
@ -478,6 +509,13 @@ public class DownloadServlet extends HttpServlet{
response.flushBuffer(); response.flushBuffer();
} }
/**
* Send message.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendMessage(HttpServletResponse response, String message) throws IOException protected void sendMessage(HttpServletResponse response, String message) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setStatus(HttpServletResponse.SC_ACCEPTED);
@ -486,6 +524,13 @@ public class DownloadServlet extends HttpServlet{
response.flushBuffer(); response.flushBuffer();
} }
/**
* Send message resource available.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendMessageResourceAvailable(HttpServletResponse response, String message) throws IOException protected void sendMessageResourceAvailable(HttpServletResponse response, String message) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setStatus(HttpServletResponse.SC_ACCEPTED);
@ -494,6 +539,13 @@ public class DownloadServlet extends HttpServlet{
response.flushBuffer(); response.flushBuffer();
} }
/**
* Send warn message.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setStatus(HttpServletResponse.SC_ACCEPTED);
@ -502,6 +554,14 @@ public class DownloadServlet extends HttpServlet{
response.flushBuffer(); response.flushBuffer();
} }
/**
* Url redirect.
*
* @param req the req
* @param response the response
* @param fakePath the fake path
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void urlRedirect(HttpServletRequest req, HttpServletResponse response, String fakePath) throws IOException { protected void urlRedirect(HttpServletRequest req, HttpServletResponse response, String fakePath) throws IOException {
String requestUrl = getRequestURL(req) +fakePath; String requestUrl = getRequestURL(req) +fakePath;
@ -511,6 +571,12 @@ public class DownloadServlet extends HttpServlet{
return; return;
} }
/**
* Gets the request url.
*
* @param req the req
* @return the request url
*/
public static String getRequestURL(HttpServletRequest req) { public static String getRequestURL(HttpServletRequest req) {
String scheme = req.getScheme(); // http String scheme = req.getScheme(); // http
@ -531,78 +597,16 @@ public class DownloadServlet extends HttpServlet{
logger.trace("server: "+url); logger.trace("server: "+url);
logger.trace("omitted contextPath: "+contextPath); logger.trace("omitted contextPath: "+contextPath);
// logger.trace("servletPath: "+servletPath);
// url.append(contextPath).append(servletPath);
// if (pathInfo != null) {
// url.append(pathInfo);
// }
// if (queryString != null) {
// url.append("?").append(queryString);
// }
PortalUrlGroupGatewayProperty p = new PortalUrlGroupGatewayProperty(); PortalUrlGroupGatewayProperty p = new PortalUrlGroupGatewayProperty();
int lenght = p.getPath().length(); int lenght = p.getPath().length();
String groupgatewaypath = "/"; String groupgatewaypath = "/";
if(lenght>1){ if(lenght>1){
String lastChar = p.getPath().substring(lenght-1, lenght-1); String lastChar = p.getPath().substring(lenght-1, lenght-1);
groupgatewaypath+= lastChar.compareTo("/")!=0?p.getPath()+"/":p.getPath(); groupgatewaypath+= lastChar.compareTo("/")!=0?p.getPath()+"/":p.getPath();
} }
url.append(groupgatewaypath); url.append(groupgatewaypath);
return url.toString(); return url.toString();
} }
/*
public static void main(String[] args) {
InputStream is = null;
logger.trace("start");
// is = GCUBEStorage.getRemoteFile("/Home/test.user/Workspace3d660604-03ef-49eb-89c3-4c73f8a47914");
try{
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome("francesco.mangiacrapa").getWorkspace();
//
// ExternalFile f = (ExternalFile) ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
WorkspaceItem wsItem = ws.getItem("907ce8ef-5c0b-4601-83ac-215d1f432f6b");
logger.trace("metadata info recovered from HL: [ID: "+wsItem.getId() +", name: "+wsItem.getName()+"]");
FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
// byte[] buffer = new byte[1024];
// int len;
// while ((len = is.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
logger.trace("cast as external file");
ExternalFile f = (ExternalFile) wsItem;
is = f.getData();
IOUtils.copy(is, out);
is.close();
out.close();
// logger.trace("Sleeping");
// Thread.sleep(20000);
// logger.trace("Alive");
logger.trace("end");
}catch (Exception e) {
e.printStackTrace();
}
}*/
} }

View File

@ -259,7 +259,7 @@ public class GWTWorkspaceBuilder {
sb.append(id); sb.append(id);
sb.append("&type="); sb.append("&type=");
sb.append(requestType.toString()); sb.append(requestType.toString());
sb.append("&"+ConstantsExplorer.CONTEXT_ID+"="); sb.append("&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"=");
sb.append(currentGroupId); sb.append(currentGroupId);
sb.append("&random="); sb.append("&random=");
sb.append(UUID.randomUUID().toString()); sb.append(UUID.randomUUID().toString());

View File

@ -22,7 +22,6 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.Image; import org.gcube.common.homelibrary.home.workspace.folder.items.Image;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.util.ImageRequestType; import org.gcube.portlets.user.workspace.client.util.ImageRequestType;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
@ -59,9 +58,10 @@ public class ImageServlet extends HttpServlet{
String imageId = req.getParameter("id"); String imageId = req.getParameter("id");
String imageType = req.getParameter("type"); String imageType = req.getParameter("type");
String contextID = req.getParameter(ConstantsExplorer.CONTEXT_ID); String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID);
String currUserId = req.getParameter(ConstantsExplorer.CURRENT_USER_ID);
logger.info("request image id: "+imageId+", type: "+imageType +", "+ConstantsExplorer.CONTEXT_ID+ ": "+contextID); logger.info("request image id: "+imageId+", type: "+imageType +", "+ConstantsExplorer.CURRENT_CONTEXT_ID+ ": "+contextID);
ImageRequestType requestType = null; ImageRequestType requestType = null;
@ -73,9 +73,7 @@ public class ImageServlet extends HttpServlet{
Workspace wa = null; Workspace wa = null;
try { try {
String currentScope= PortalContext.getConfiguration().getCurrentScope(contextID); wa = WsUtil.getWorkspace(req, contextID, currUserId);
logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope);
wa = WsUtil.getWorkspace(req, currentScope);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error during workspace retrieving", e); logger.error("Error during workspace retrieving", e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving"); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving");

View File

@ -27,6 +27,7 @@ import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParame
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE; import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
@ -147,25 +148,47 @@ public class WsUtil {
} }
/** /**
* Gets the workspace. * Gets the workspace.
* *
* @param httpServletRequest the http servlet request * @param httpServletRequest the http servlet request
* @param useThisScope the use this scope * @param contextID the context id
* @param currUserId the curr user id
* @return the workspace * @return the workspace
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception * @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/ */
public static Workspace getWorkspace(HttpServletRequest httpServletRequest, String useThisScope) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException public static Workspace getWorkspace(HttpServletRequest httpServletRequest, String contextID, String currUserId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{ {
logger.trace("Get Workspace"); logger.trace("Get Workspace");
PortalContextInfo info = getPortalContext(httpServletRequest, useThisScope); String currentScope = PortalContext.getConfiguration().getCurrentScope(contextID);
logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope);
PortalContextInfo info = getPortalContext(httpServletRequest, currentScope);
logger.trace("PortalContextInfo: "+info); logger.trace("PortalContextInfo: "+info);
ScopeProvider.instance.set(info.getCurrentScope()); ScopeProvider.instance.set(info.getCurrentScope());
logger.trace("Scope provider instancied"); logger.trace("Scope provider instancied");
String username = null;
try {
GCubeUser gCubeUser = new LiferayUserManager().getUserById(Long.valueOf(currUserId));
logger.debug("Gcube user read from liferay: "+gCubeUser);
if(gCubeUser!=null && gCubeUser.getUsername()!=null)
username = gCubeUser.getUsername();
} catch (Exception e) {
String error = "Error retrieving gCubeUser for: [userId= "
+ currUserId + ", scope: " + currentScope + "]";
logger.error(error, e);
}
if(username==null || username.isEmpty())
username = PortalContext.getConfiguration().getCurrentUser(httpServletRequest).getUsername();
//overriding username
info.setUsername(username);
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername()); Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
return workspace; return workspace;