From aaa9799db3f90cf7b97e842d7019e52b3590727c Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 25 Nov 2016 13:31:52 +0000 Subject: [PATCH] Added INJECTED scope git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@134795 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../RequestBuilderWorkspaceValidateItem.java | 54 ++++++++++--------- .../workspace/server/DownloadServlet.java | 7 ++- .../user/workspace/server/util/WsUtil.java | 39 ++++++++++++++ 3 files changed, 73 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java b/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java index cf1bf4c..f08793f 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/util/RequestBuilderWorkspaceValidateItem.java @@ -1,8 +1,9 @@ /** - * + * */ package org.gcube.portlets.user.workspace.client.util; +import org.gcube.portal.clientcontext.client.GCubeClientContext; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.event.SessionExpiredEvent; @@ -22,19 +23,19 @@ import com.google.gwt.user.client.rpc.AsyncCallback; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Jun 24, 2013 - * + * */ public class RequestBuilderWorkspaceValidateItem { - + /** - * + * */ protected static final int TIME_INFO_DISPLAY = 1500; //milliseconds private AsyncCallback callback; private String parameters; - + /** - * + * * @param method * @param servletName the name of the servlet that must be called * @param params param=value¶m1=value1&... @@ -43,55 +44,56 @@ public class RequestBuilderWorkspaceValidateItem { * @throws Exception */ public RequestBuilderWorkspaceValidateItem(RequestBuilder.Method method, String servletName, final String params, final String targetWindow, final AsyncCallback callback) throws Exception{ - + this.callback = callback; - + final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", targetWindow, ""); - + this.parameters = params; - + if(servletName==null) return; servletName = servletName.isEmpty()?"/":servletName; - + if(!servletName.contains("/")) servletName+="/"+servletName; - + if(parameters==null) parameters = ConstantsExplorer.VALIDATEITEM+"=true"; else parameters +="&"+ConstantsExplorer.VALIDATEITEM+"=true"; - + String urlRequest = servletName+"?"+parameters; - + GWT.log("request builder for: "+urlRequest); - + RequestBuilder requestBuilder = new RequestBuilder(method, urlRequest); + GCubeClientContext.injectContext(requestBuilder); new InfoDisplayMessage("Download", "Requesting...", TIME_INFO_DISPLAY); try { - + requestBuilder.sendRequest("", new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { - + int status = response.getStatusCode(); // System.out.println("status code is "+status); - - if(!(status==200) && !(status==202)){ //NOT IS STATUS SC_ACCEPTED - + + if(!(status==200) && !(status==202)){ //NOT IS STATUS SC_ACCEPTED + if(status==401){ // SC_UNAUTHORIZED = 401; GWT.log("Session expired"); AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent()); return; - } + } newBrowserWindow.close(); handleError("Sorry, an error occurred on retriving the file. "+response.getText()); //ERROR STATUS }else { //OK STATUS - + if(callback!=null) callback.onSuccess(new WindowOpenParameter(targetWindow, "", params, true, newBrowserWindow)); } @@ -100,7 +102,7 @@ public class RequestBuilderWorkspaceValidateItem { @Override public void onError(Request request, Throwable exception) { newBrowserWindow.close(); - + if(exception instanceof SessionExpiredException){ GWT.log("Session expired"); AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent()); @@ -111,19 +113,19 @@ public class RequestBuilderWorkspaceValidateItem { handleError(exception.getMessage()); } }); - + } catch (RequestException e) { newBrowserWindow.close(); throw new Exception("Sorry, an error occurred while contacting server, try again"); } } - + public void handleError(String message){ if(callback!=null) callback.onFailure(new Exception(message)); else new MessageBoxAlert("Error", message, null); - + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java index 908347a..c82a792 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java @@ -35,6 +35,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries; import org.gcube.common.homelibrary.util.Extensions; import org.gcube.common.homelibrary.util.MimeTypeUtil; 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.server.property.PortalUrlGroupGatewayProperty; import org.gcube.portlets.user.workspace.server.util.WsUtil; @@ -67,6 +68,7 @@ public class DownloadServlet extends HttpServlet{ 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"); + logger.trace("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+"]"); if(itemId==null || itemId.isEmpty()){ sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null"); @@ -80,7 +82,10 @@ public class DownloadServlet extends HttpServlet{ if(WsUtil.isSessionExpired(req)) throw new SessionExpiredException(); - wa = WsUtil.getWorkspace(req); + PortalContext pContext = PortalContext.getConfiguration(); + String currentScope = pContext.getCurrentScope(req); + logger.info("INJECTED Scope "+currentScope); + wa = WsUtil.getWorkspace(req, currentScope); } catch (Exception e) { if (e instanceof SessionExpiredException){ diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java index 3b30463..d59305b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java @@ -96,6 +96,20 @@ public class WsUtil { } + /** + * Gets the portal context. + * + * @param httpServletRequest the http servlet request + * @param overrideScope the override scope + * @return the portal context + */ + public static PortalContextInfo getPortalContext(HttpServletRequest httpServletRequest, String overrideScope){ + PortalContextInfo info = getPortalContext(httpServletRequest); + info.setCurrentScope(overrideScope); + return info; + } + + /** * Checks if is session expired. * @@ -134,6 +148,31 @@ public class WsUtil { } + + /** + * Gets the workspace. + * + * @param httpServletRequest the http servlet request + * @param useThisScope the use this scope + * @return the workspace + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public static Workspace getWorkspace(HttpServletRequest httpServletRequest, String useThisScope) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException + { + logger.trace("Get Workspace"); + PortalContextInfo info = getPortalContext(httpServletRequest, useThisScope); + logger.trace("PortalContextInfo: "+info); + + ScopeProvider.instance.set(info.getCurrentScope()); + logger.trace("Scope provider instancied"); + + Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername()); + return workspace; + + } + /** * Gets the GWT workspace builder. *