146 lines
4.0 KiB
Java
146 lines
4.0 KiB
Java
package org.gcube.portlets.user.dataminermanager.client;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.DataMinerWorkAreaEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.SessionExpiredEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
|
|
import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaEventType;
|
|
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
|
|
import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException;
|
|
import org.gcube.portlets.user.dataminermanager.shared.session.UserInfo;
|
|
import org.gcube.portlets.user.dataminermanager.shared.workspace.DataMinerWorkArea;
|
|
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.event.shared.EventBus;
|
|
import com.google.gwt.user.client.Timer;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class DataMinerManagerController {
|
|
private EventBus eventBus;
|
|
private UserInfo userInfo;
|
|
private DataMinerWorkArea dataMinerWorkArea;
|
|
|
|
public DataMinerManagerController() {
|
|
eventBus = EventBusProvider.INSTANCE;
|
|
init();
|
|
}
|
|
|
|
public UserInfo getUserInfo() {
|
|
return userInfo;
|
|
}
|
|
|
|
public DataMinerWorkArea getDataMinerWorkArea() {
|
|
return dataMinerWorkArea;
|
|
}
|
|
|
|
private void init() {
|
|
callHello();
|
|
checkSession();
|
|
bindToEvents();
|
|
}
|
|
|
|
private void checkSession() {
|
|
// if you do not need to something when the session expire
|
|
CheckSession.getInstance().startPolling();
|
|
}
|
|
|
|
private void sessionExpiredShow() {
|
|
CheckSession.showLogoutDialog();
|
|
}
|
|
|
|
private void sessionExpiredShowDelayed() {
|
|
Timer timeoutTimer = new Timer() {
|
|
public void run() {
|
|
sessionExpiredShow();
|
|
|
|
}
|
|
};
|
|
int TIMEOUT = 3; // 3 second timeout
|
|
|
|
timeoutTimer.schedule(TIMEOUT * 1000); // timeout is in milliseconds
|
|
|
|
}
|
|
|
|
private void callHello() {
|
|
DataMinerPortletServiceAsync.INSTANCE
|
|
.hello(new AsyncCallback<UserInfo>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Log.info("No valid user found: " + caught.getMessage());
|
|
if (caught instanceof ExpiredSessionServiceException) {
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
sessionExpiredShowDelayed();
|
|
} else {
|
|
UtilsGXT3.alert(
|
|
"Error",
|
|
"No user found: "
|
|
+ caught.getLocalizedMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(UserInfo result) {
|
|
userInfo = result;
|
|
Log.info("Hello: " + userInfo.getUsername());
|
|
retrieveDataMinerWorkArea();
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void bindToEvents() {
|
|
|
|
EventBusProvider.INSTANCE.addHandler(SessionExpiredEvent.TYPE,
|
|
new SessionExpiredEvent.SessionExpiredEventHandler() {
|
|
|
|
@Override
|
|
public void onChange(SessionExpiredEvent event) {
|
|
Log.debug("Catch Event SessionExpiredEvent");
|
|
sessionExpiredShow();
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void retrieveDataMinerWorkArea() {
|
|
DataMinerPortletServiceAsync.INSTANCE
|
|
.getDataMinerWorkArea(new AsyncCallback<DataMinerWorkArea>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Log.info("No valid user found: " + caught.getMessage());
|
|
if (caught instanceof ExpiredSessionServiceException) {
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
sessionExpiredShowDelayed();
|
|
} else {
|
|
UtilsGXT3.alert("Error",
|
|
"Error retrieving DataMiner work area info: "
|
|
+ caught.getLocalizedMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(DataMinerWorkArea result) {
|
|
Log.debug("DataMinerWorkArea: " + result);
|
|
dataMinerWorkArea = result;
|
|
DataMinerWorkAreaEvent dataMinerWorkAreaEvent = new DataMinerWorkAreaEvent(
|
|
DataMinerWorkAreaEventType.UPDATE, result);
|
|
eventBus.fireEvent(dataMinerWorkAreaEvent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|