tabular-data-table-widget/src/main/java/org/gcube/portlets/user/td/tablewidget/client/CloneTabularResource.java

123 lines
3.9 KiB
Java

package org.gcube.portlets.user.td.tablewidget.client;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog;
import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener;
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.OperationResult;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.web.bindery.event.shared.EventBus;
public class CloneTabularResource implements MonitorDialogListener {
protected TRId trId;
protected EventBus eventBus;
protected CloneTabularResourceSession cloneTabularResourceSession;
public CloneTabularResource(TRId trId, EventBus eventBus) {
this.trId = trId;
this.eventBus = eventBus;
}
public void cloneTR() {
cloneTabularResourceSession = new CloneTabularResourceSession(trId);
onCloneTR();
}
protected void onCloneTR() {
TDGWTServiceAsync.INSTANCE.startCloneTabularResource(
cloneTabularResourceSession, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
if (caught instanceof TDGWTIsLockedException) {
Log.error(caught.getLocalizedMessage());
UtilsGXT3.alert("Error Locked",
caught.getLocalizedMessage());
} else {
Log.debug("Clone Error: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert(
"Error Cloning Tabular Resource",
"Error in clone operation!");
}
}
}
public void onSuccess(String taskId) {
Log.debug("Start TR Clone");
openMonitorDialog(taskId);
}
});
}
protected void close() {
/*
* if (parent != null) { parent.close(); }
*/
}
// /
protected void openMonitorDialog(String taskId) {
MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus);
monitorDialog.addProgressDialogListener(this);
monitorDialog.show();
}
@Override
public void operationComplete(OperationResult operationResult) {
ChangeTableWhy why = ChangeTableWhy.TABLECLONED;
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
ChangeTableRequestType.CLONETABULARRESOURCE, operationResult.getTrId(), why);
eventBus.fireEvent(changeTableRequestEvent);
close();
}
@Override
public void operationFailed(Throwable caught, String reason, String details) {
UtilsGXT3.alert(reason, details);
close();
}
@Override
public void operationStopped(OperationResult operationResult, String reason, String details) {
ChangeTableWhy why = ChangeTableWhy.TABLECURATION;
ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent(
ChangeTableRequestType.CLONETABULARRESOURCE, operationResult.getTrId(), why);
eventBus.fireEvent(changeTableRequestEvent);
close();
}
@Override
public void operationAborted() {
close();
}
@Override
public void operationPutInBackground() {
close();
}
}