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
This commit is contained in:
Giancarlo Panichi 2015-03-09 18:02:26 +00:00
parent 232c19ae70
commit 3112549ab3
1 changed files with 40 additions and 9 deletions

View File

@ -1,10 +1,16 @@
package org.gcube.portlets.user.td.client.rstudio; 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 org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.EventBus;
/** /**
@ -18,24 +24,49 @@ import com.google.web.bindery.event.shared.EventBus;
*/ */
public class RStudio { public class RStudio {
private static final String TAB_RESOURCE_ID_PARAMETER = "TabResourceId"; private static final String TAB_RESOURCE_ID_PARAMETER = "TabResourceId";
private TRId trId;
private EventBus eventBus;
public RStudio(TRId trId, 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); Log.debug("Request: " + trId);
String url = GWT.getModuleBaseURL() + "TDRStudioServlet?" String url = GWT.getModuleBaseURL() + "TDRStudioServlet?"
+ TAB_RESOURCE_ID_PARAMETER + "=" + TAB_RESOURCE_ID_PARAMETER + "=" + trId.getId();
+ trId.getId();
Log.debug("Server URL: " + url); Log.debug("Server URL: " + url);
Window.open(url, "RStudio", ""); Window.open(url, "RStudio", "");
} }
private void callCheckSession() {
TDGWTServiceAsync.INSTANCE.hello(new AsyncCallback<UserInfo>() {
@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();
}
});
}
} }