You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
480 lines
14 KiB
Java
480 lines
14 KiB
Java
package org.gcube.portlets.user.dataminermanager.client;
|
|
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.ComputationItem;
|
|
import org.gcube.portlets.user.dataminermanager.client.bean.OperatorsClassification;
|
|
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.CancelComputationExecutionRequestEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.DataMinerWorkAreaEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.RefreshDataMinerWorkAreaEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.DeleteItemRequestEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.OperatorsClassificationEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.OperatorsClassificationRequestEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.ResubmitComputationExecutionEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.ResubmitComputationExecutionRequestEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.SessionExpiredEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.StartComputationExecutionEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.events.StartComputationExecutionRequestEvent;
|
|
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
|
|
import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType;
|
|
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.Constants;
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.ComputationId;
|
|
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.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 UserInfo userInfo;
|
|
private DataMinerWorkArea dataMinerWorkArea;
|
|
private List<OperatorsClassification> operatorsClassifications;
|
|
|
|
public DataMinerManagerController() {
|
|
init();
|
|
}
|
|
|
|
public UserInfo getUserInfo() {
|
|
return userInfo;
|
|
}
|
|
|
|
public DataMinerWorkArea getDataMinerWorkArea() {
|
|
return dataMinerWorkArea;
|
|
}
|
|
|
|
private void init() {
|
|
bind();
|
|
callHello();
|
|
checkSession();
|
|
}
|
|
|
|
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 bind() {
|
|
|
|
EventBusProvider.INSTANCE.addHandler(SessionExpiredEvent.TYPE,
|
|
new SessionExpiredEvent.SessionExpiredEventHandler() {
|
|
|
|
@Override
|
|
public void onChange(SessionExpiredEvent event) {
|
|
Log.debug("Catch SessionExpiredEvent");
|
|
sessionExpiredShow();
|
|
|
|
}
|
|
});
|
|
|
|
EventBusProvider.INSTANCE
|
|
.addHandler(
|
|
StartComputationExecutionRequestEvent.TYPE,
|
|
new StartComputationExecutionRequestEvent.StartComputationExecutionRequestEventHandler() {
|
|
|
|
@Override
|
|
public void onStart(
|
|
StartComputationExecutionRequestEvent event) {
|
|
Log.debug("Catch StartComputationExecutionRequestEvent: "
|
|
+ event);
|
|
startComputationRequest(event);
|
|
|
|
}
|
|
});
|
|
|
|
EventBusProvider.INSTANCE
|
|
.addHandler(
|
|
CancelComputationExecutionRequestEvent.TYPE,
|
|
new CancelComputationExecutionRequestEvent.CancelComputationExecutionRequestEventHandler() {
|
|
|
|
@Override
|
|
public void onCancel(
|
|
CancelComputationExecutionRequestEvent event) {
|
|
Log.debug("Catch CancelComputationRequestEvent: "
|
|
+ event);
|
|
cancelComputationRequest(event);
|
|
|
|
}
|
|
});
|
|
|
|
EventBusProvider.INSTANCE
|
|
.addHandler(
|
|
ResubmitComputationExecutionRequestEvent.TYPE,
|
|
new ResubmitComputationExecutionRequestEvent.ResubmitComputationExecutionRequestEventHandler() {
|
|
|
|
@Override
|
|
public void onResubmit(
|
|
ResubmitComputationExecutionRequestEvent event) {
|
|
Log.debug("Catch ResubmitComputationExecutionRequestEvent: "
|
|
+ event);
|
|
resubmitComputationRequest(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
EventBusProvider.INSTANCE
|
|
.addHandler(
|
|
OperatorsClassificationRequestEvent.TYPE,
|
|
new OperatorsClassificationRequestEvent.OperatorsClassificationRequestEventHandler() {
|
|
|
|
@Override
|
|
public void onRequest(
|
|
OperatorsClassificationRequestEvent event) {
|
|
Log.debug("Catch OperatorsClassificationRequestEvent: "
|
|
+ event);
|
|
operatorsClassificationRequest(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
EventBusProvider.INSTANCE.addHandler(DeleteItemRequestEvent.TYPE,
|
|
new DeleteItemRequestEvent.DeleteItemRequestEventHandler() {
|
|
|
|
@Override
|
|
public void onDeleteRequest(DeleteItemRequestEvent event) {
|
|
Log.debug("Catch DeleteItemRequestEvent: " + event);
|
|
deleteItemRequest(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/*
|
|
* EventBusProvider.INSTANCE.addHandler(
|
|
* ResubmitComputationEvent.getType(), new
|
|
* ResubmitComputationEvent.ResubmitComputationHandler() {
|
|
*
|
|
* @Override public void onResubmitComputation( ResubmitComputationEvent
|
|
* event) { switchTo(experimentPanel);
|
|
* header.setMenuSelected(MenuItem.EXPERIMENT); } });
|
|
*/
|
|
|
|
}
|
|
|
|
private void startComputationRequest(
|
|
final StartComputationExecutionRequestEvent event) {
|
|
|
|
DataMinerPortletServiceAsync.INSTANCE.startComputation(event.getOp(),
|
|
event.getComputationTitle(), event.getComputationDescription(),
|
|
new AsyncCallback<ComputationId>() {
|
|
@Override
|
|
public void onSuccess(ComputationId computationId) {
|
|
if (computationId == null)
|
|
UtilsGXT3.alert("Error",
|
|
"Failed to start computation "
|
|
+ event.getOp().getName()
|
|
+ ", the computation id is null");
|
|
else {
|
|
startComputation(computationId,
|
|
event.getComputationStatusPanelIndex());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
UtilsGXT3.alert("Error",
|
|
"Failed to start computation "
|
|
+ event.getOp().getName()
|
|
+ "<br/>Cause:" + caught.getCause()
|
|
+ "<br/>Message:" + caught.getMessage());
|
|
caught.printStackTrace();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void startComputation(ComputationId computationId,
|
|
int computationStatusPanelIndex) {
|
|
StartComputationExecutionEvent event = new StartComputationExecutionEvent(
|
|
computationId, computationStatusPanelIndex);
|
|
EventBusProvider.INSTANCE.fireEvent(event);
|
|
}
|
|
|
|
private void cancelComputationRequest(
|
|
CancelComputationExecutionRequestEvent event) {
|
|
final ComputationId computationId = event.getComputationId();
|
|
|
|
DataMinerPortletServiceAsync.INSTANCE.cancelComputation(computationId,
|
|
new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof ExpiredSessionServiceException) {
|
|
UtilsGXT3.alert("Error", "Expired Session");
|
|
EventBusProvider.INSTANCE
|
|
.fireEvent(new SessionExpiredEvent());
|
|
} else {
|
|
UtilsGXT3.alert(
|
|
"Error",
|
|
"Error in cancel computation: ComputationId="
|
|
+ computationId.getId()
|
|
+ ", Error="
|
|
+ caught.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(String result) {
|
|
Log.debug("Computation Deleted!");
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void resubmitComputationRequest(
|
|
final ResubmitComputationExecutionRequestEvent event) {
|
|
DataMinerPortletServiceAsync.INSTANCE.resubmit(
|
|
event.getComputationId(), new AsyncCallback<ComputationId>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
UtilsGXT3
|
|
.alert("Error",
|
|
"Failed to resubmit computation "
|
|
+ event.getComputationId()
|
|
+ "<br/>Cause:"
|
|
+ caught.getCause()
|
|
+ "<br/>Message:"
|
|
+ caught.getMessage());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ComputationId result) {
|
|
if (result == null)
|
|
UtilsGXT3
|
|
.alert("Error",
|
|
"Failed to resubmit computation, the computation id is null!");
|
|
else {
|
|
resubmitComputation(result);
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void resubmitComputation(ComputationId computationId) {
|
|
ComputationItem computationItem = new ComputationItem(computationId,
|
|
null);
|
|
ResubmitComputationExecutionEvent event = new ResubmitComputationExecutionEvent(
|
|
computationItem);
|
|
EventBusProvider.INSTANCE.fireEvent(event);
|
|
}
|
|
|
|
private void operatorsClassificationRequest(
|
|
OperatorsClassificationRequestEvent event) {
|
|
if (operatorsClassifications == null) {
|
|
getOperatorsClassifications(event);
|
|
} else {
|
|
if (event.getOperatorsClassificationRequestType() == null) {
|
|
return;
|
|
}
|
|
switch (event.getOperatorsClassificationRequestType()) {
|
|
case ByName:
|
|
getOperatorsClassificationByName(event);
|
|
break;
|
|
case Default:
|
|
getOperatorsClassificationDefault(event);
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void getOperatorsClassifications(
|
|
final OperatorsClassificationRequestEvent event) {
|
|
DataMinerPortletServiceAsync.INSTANCE
|
|
.getOperatorsClassifications(new AsyncCallback<List<OperatorsClassification>>() {
|
|
|
|
@Override
|
|
public void onSuccess(List<OperatorsClassification> result) {
|
|
operatorsClassifications = result;
|
|
operatorsClassificationRequest(event);
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
UtilsGXT3.alert("Error",
|
|
"Error retrieving operators classification! "
|
|
+ caught.getLocalizedMessage());
|
|
Log.error("Error retrieving operators classification: "
|
|
+ caught.getLocalizedMessage());
|
|
caught.printStackTrace();
|
|
}
|
|
});
|
|
}
|
|
|
|
private void getOperatorsClassificationDefault(
|
|
OperatorsClassificationRequestEvent event) {
|
|
OperatorsClassification find = null;
|
|
for (OperatorsClassification oc : operatorsClassifications) {
|
|
if (oc.getName().equals(Constants.UserClassificationName)) {
|
|
find = oc;
|
|
break;
|
|
}
|
|
}
|
|
OperatorsClassificationEvent ocEvent = new OperatorsClassificationEvent(
|
|
find);
|
|
EventBusProvider.INSTANCE.fireEvent(ocEvent);
|
|
}
|
|
|
|
private void getOperatorsClassificationByName(
|
|
OperatorsClassificationRequestEvent event) {
|
|
OperatorsClassification find = null;
|
|
for (OperatorsClassification oc : operatorsClassifications) {
|
|
if (oc.getName().equals(event.getClassificationName())) {
|
|
find = oc;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (find == null) {
|
|
for (OperatorsClassification oc : operatorsClassifications) {
|
|
if (oc.getName().equals(Constants.UserClassificationName)) {
|
|
find = oc;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
OperatorsClassificationEvent ocEvent = new OperatorsClassificationEvent(
|
|
event.getClassificationName(), find);
|
|
EventBusProvider.INSTANCE.fireEvent(ocEvent);
|
|
}
|
|
|
|
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);
|
|
fireDataMinerWorkAreaEventRetrieved(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void fireDataMinerWorkAreaEventRetrieved(DataMinerWorkArea result) {
|
|
dataMinerWorkArea = result;
|
|
DataMinerWorkAreaEvent dataMinerWorkAreaEvent = new DataMinerWorkAreaEvent(
|
|
DataMinerWorkAreaEventType.OPEN, result);
|
|
EventBusProvider.INSTANCE.fireEvent(dataMinerWorkAreaEvent);
|
|
}
|
|
|
|
private void deleteItemRequest(final DeleteItemRequestEvent event) {
|
|
DataMinerPortletServiceAsync.INSTANCE
|
|
.deleteItem(event.getItemDescription(), new AsyncCallback<Void>() {
|
|
|
|
@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 deleting item on workspace: "
|
|
+ caught.getLocalizedMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
Log.debug("Deleted Item!");
|
|
fireRefreshDataMinerWorkAreaEvent(event.getDataMinerWorkAreaElementType());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
private void fireRefreshDataMinerWorkAreaEvent(
|
|
DataMinerWorkAreaElementType dataMinerWorkAreaElementType) {
|
|
RefreshDataMinerWorkAreaEvent refreshEvent=new RefreshDataMinerWorkAreaEvent(dataMinerWorkAreaElementType);
|
|
EventBusProvider.INSTANCE.fireEvent(refreshEvent);
|
|
|
|
}
|
|
|
|
}
|