From 3112549ab397fc3a28a937a61be3cf59bb7008dc Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 9 Mar 2015 18:02:26 +0000 Subject: [PATCH] Fixed session check on RStudio git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-portlet@113534 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/td/client/rstudio/RStudio.java | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/client/rstudio/RStudio.java b/src/main/java/org/gcube/portlets/user/td/client/rstudio/RStudio.java index 580bcea..35c4e01 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/rstudio/RStudio.java +++ b/src/main/java/org/gcube/portlets/user/td/client/rstudio/RStudio.java @@ -1,10 +1,16 @@ package org.gcube.portlets.user.td.client.rstudio; +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; /** @@ -18,24 +24,49 @@ import com.google.web.bindery.event.shared.EventBus; */ public class RStudio { private static final String TAB_RESOURCE_ID_PARAMETER = "TabResourceId"; - - + private TRId trId; + private EventBus eventBus; + public RStudio(TRId trId, EventBus eventBus) { - callRStudioServlet(trId); + this.trId = trId; + this.eventBus = eventBus; + callCheckSession(); + } - - private void callRStudioServlet(TRId trId) { + + private void callRStudioServlet() { Log.debug("Request: " + trId); String url = GWT.getModuleBaseURL() + "TDRStudioServlet?" - + TAB_RESOURCE_ID_PARAMETER + "=" - + trId.getId(); + + TAB_RESOURCE_ID_PARAMETER + "=" + trId.getId(); Log.debug("Server URL: " + url); Window.open(url, "RStudio", ""); - } - + private void callCheckSession() { + TDGWTServiceAsync.INSTANCE.hello(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Log.info("No valid user found: " + caught.getMessage()); + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } + } + + @Override + public void onSuccess(UserInfo result) { + Log.info("Hello: " + result.getUsername()); + callRStudioServlet(); + } + + }); + + } }