use of org.activityinfo.promise.PromisesExecutionMonitor in project activityinfo by bedatadriven.
the class ImportPresenter method persistData.
protected void persistData() {
persistFinished = false;
persistFailed = false;
dialogBox.getFinishButton().setEnabled(false);
dialogBox.setStatusText(I18N.CONSTANTS.importing());
PromisesExecutionMonitor monitor = new PromisesExecutionMonitor() {
@Override
public void onChange(PromisesExecutionStatistic statistic) {
lastStatistic = statistic;
if (persistFinished) {
if (persistFailed) {
showFailure();
}
} else {
dialogBox.setStatusText(I18N.MESSAGES.importingData(statistic.getCompleted(), statistic.getTotal(), statistic.getRetries()));
}
}
};
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
persistFinished = true;
persistFailed = true;
Log.error(caught.getMessage(), caught);
showDelayedFailure();
}
@Override
public void onSuccess(Void result) {
persistFinished = true;
overlay.hide();
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
eventBus.fireEvent(new ImportResultEvent(true));
}
});
}
};
if (retryFailedRows) {
importer.getResourceLocator().persistOperation(lastStatistic.getNotFinishedOperations(), monitor).then(callback);
retryFailedRows = false;
return;
}
importer.persist(importModel, monitor).then(callback);
}
Aggregations