258 lines
7.5 KiB
Java
258 lines
7.5 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.td.sdmxexportwidget.client;
|
|
|
|
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.monitor.OperationMonitor;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.MonitorBarUpdater;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.MonitorUpdater;
|
|
import org.gcube.portlets.user.td.monitorwidget.client.MonitorUpdaterListener;
|
|
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.wizardwidget.client.WizardCard;
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.widget.core.client.FramedPanel;
|
|
import com.sencha.gxt.widget.core.client.ProgressBar;
|
|
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer;
|
|
import com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.VBoxLayoutAlign;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent;
|
|
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
|
|
|
|
/**
|
|
*
|
|
* @author "Giancarlo Panichi" <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class SDMXOperationInProgressCard extends WizardCard implements
|
|
MonitorUpdaterListener {
|
|
|
|
public static final int STATUS_POLLING_DELAY = 1000;
|
|
protected SDMXOperationInProgressCard thisCard;
|
|
protected SDMXExportSession exportSession;
|
|
protected MonitorUpdater progressUpdater;
|
|
protected ProgressBar progressBar;
|
|
|
|
public SDMXOperationInProgressCard(final SDMXExportSession exportSession) {
|
|
super("Operation In Progress", "");
|
|
|
|
this.exportSession = exportSession;
|
|
thisCard = this;
|
|
String urlRegistry;
|
|
if (exportSession.getRegistryBaseUrl() == null
|
|
|| exportSession.getRegistryBaseUrl().isEmpty()) {
|
|
urlRegistry = "Internal";
|
|
} else {
|
|
urlRegistry = exportSession.getRegistryBaseUrl();
|
|
}
|
|
|
|
VBoxLayoutContainer operationInProgressPanel = new VBoxLayoutContainer();
|
|
operationInProgressPanel.setVBoxLayoutAlign(VBoxLayoutAlign.CENTER);
|
|
|
|
final FlexTable description = new FlexTable();
|
|
// FlexCellFormatter cellFormatter = description.getFlexCellFormatter();
|
|
description.setCellSpacing(10);
|
|
description.setCellPadding(4);
|
|
description.setBorderWidth(0);
|
|
|
|
// display:block;vertical-align:text-top;
|
|
description.setHTML(0, 0,
|
|
"<span style=\"font-weight:bold;\";>Destination: </span>");
|
|
description.setText(0, 1, exportSession.getSource().getName());
|
|
|
|
description.setHTML(1, 0,
|
|
"<span style=\"font-weight:bold;\";>Id: </span>");
|
|
description.setText(1, 1, exportSession.getId());
|
|
|
|
description.setHTML(2, 0,
|
|
"<span style=\"font-weight:bold;\";>Agency: </span>");
|
|
description.setText(2, 1, exportSession.getAgencyName());
|
|
|
|
description.setHTML(3, 0,
|
|
"<span style=\"font-weight:bold;\";>Registry: </span>");
|
|
description.setText(3, 1, urlRegistry);
|
|
|
|
description.setHTML(4, 0,
|
|
"<span style=\"font-weight:bold;\";>Version: </span>");
|
|
description.setText(4, 1, exportSession.getVersion());
|
|
|
|
FramedPanel summary = new FramedPanel();
|
|
summary.setHeadingText("Export Summary");
|
|
summary.setWidth(400);
|
|
summary.add(description);
|
|
operationInProgressPanel.add(summary, new BoxLayoutData(new Margins(20,
|
|
5, 10, 5)));
|
|
|
|
ProgressBar progressBar = new ProgressBar();
|
|
operationInProgressPanel.add(progressBar, new BoxLayoutData(
|
|
new Margins(10, 5, 10, 5)));
|
|
|
|
|
|
setContent(operationInProgressPanel);
|
|
|
|
}
|
|
|
|
// columnToImportMask
|
|
|
|
public void exportSDMX() {
|
|
TDGWTServiceAsync.INSTANCE.startSDMXExport(exportSession,
|
|
new AsyncCallback<String>() {
|
|
|
|
public void onSuccess(String taskId) {
|
|
OperationMonitorSession operationMonitorSession = new OperationMonitorSession(
|
|
taskId);
|
|
progressUpdater = new MonitorUpdater(
|
|
operationMonitorSession);
|
|
progressUpdater.addListener(new MonitorBarUpdater(
|
|
progressBar));
|
|
|
|
progressUpdater.addListener(thisCard);
|
|
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
|
|
|
|
}
|
|
|
|
public void onFailure(Throwable caught) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
getEventBus()
|
|
.fireEvent(
|
|
new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
|
|
showErrorAndHide(
|
|
"Error in exportSDMX",
|
|
"An error occured in exportSDMX: "
|
|
+ caught.getLocalizedMessage(),
|
|
caught.getStackTrace().toString(), caught);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void setup() {
|
|
getWizardWindow().setEnableBackButton(false);
|
|
setBackButtonVisible(false);
|
|
setNextButtonVisible(false);
|
|
getWizardWindow().setEnableNextButton(false);
|
|
getWizardWindow().setNextButtonToFinish();
|
|
exportSDMX();
|
|
}
|
|
|
|
@Override
|
|
public void monitorInitializing(OperationMonitor operationMonitor) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorUpdate(OperationMonitor operationMonitor) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorComplete(final TRId trId) {
|
|
|
|
Command sayComplete = new Command() {
|
|
public void execute() {
|
|
try {
|
|
getWizardWindow().close(false);
|
|
Log.info("fire Complete: " + trId);
|
|
|
|
getWizardWindow().fireCompleted(trId);
|
|
|
|
} catch (Exception e) {
|
|
Log.error("fire Complete :" + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
};
|
|
|
|
getWizardWindow().setNextButtonCommand(sayComplete);
|
|
|
|
setNextButtonVisible(true);
|
|
getWizardWindow().setEnableNextButton(true);
|
|
}
|
|
|
|
@Override
|
|
public void monitorFailed(Throwable caught, String reason,
|
|
String failureDetails) {
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
getEventBus()
|
|
.fireEvent(
|
|
new SessionExpiredEvent(
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
} else {
|
|
AlertMessageBox d = new AlertMessageBox(
|
|
"Error in Codelist Mapping Import", reason);
|
|
d.addHideHandler(new HideHandler() {
|
|
public void onHide(HideEvent event) {
|
|
}
|
|
});
|
|
d.show();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void monitorStopped(final TRId trId, String reason, String details) {
|
|
|
|
Command sayComplete = new Command() {
|
|
public void execute() {
|
|
try {
|
|
getWizardWindow().close(false);
|
|
Log.info("fire Complete: tabular resource " + trId.getId());
|
|
Log.info("fire Complete: tableId " + trId.getTableId());
|
|
|
|
getWizardWindow().fireCompleted(trId);
|
|
|
|
} catch (Exception e) {
|
|
Log.error("fire Complete :" + e.getLocalizedMessage());
|
|
}
|
|
}
|
|
};
|
|
|
|
getWizardWindow().setNextButtonCommand(sayComplete);
|
|
|
|
setNextButtonVisible(true);
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorGeneratingView(OperationMonitor operationMonitor) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorValidate(OperationMonitor operationMonitor) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public void monitorAborted() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void monitorPutInBackground() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
}
|