diff --git a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/progress/CSVImportProgressUpdater.java b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/progress/CSVImportProgressUpdater.java
index a3e058d..7c7dcee 100644
--- a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/progress/CSVImportProgressUpdater.java
+++ b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/progress/CSVImportProgressUpdater.java
@@ -9,125 +9,136 @@ import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
-
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
- * This {@link Timer} retrieves {@link OperationProgress} from the specified {@link OperationProgressSource} with the scheduled interval.
- * The retrieved information are spread to the subscribed {@link CSVImportProgressListener}.
+ * This {@link Timer} retrieves {@link OperationProgress} from the specified
+ * {@link OperationProgressSource} with the scheduled interval. The retrieved
+ * information are spread to the subscribed {@link CSVImportProgressListener}.
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
*
- * @author "Giancarlo Panichi"
- * g.panichi@isti.cnr.it
- *
*/
public class CSVImportProgressUpdater extends Timer {
protected ArrayList listeners = new ArrayList();
-
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting operation progress");
- TDGWTServiceAsync.INSTANCE.getCSVImportMonitor(new AsyncCallback() {
+ TDGWTServiceAsync.INSTANCE
+ .getCSVImportMonitor(new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ cancel();
+ Log.error("Error retrieving the operation state",
+ caught);
+ String message = getStack(caught);
+ fireOperationFailed(caught,
+ "Failed getting operation updates", message);
+ }
+
+ @Override
+ public void onSuccess(CSVImportMonitor result) {
+ Log.info("retrieved CSVImportMonitor: "
+ + result.getStatus());
+ switch (result.getStatus()) {
+ case INITIALIZING:
+ Log.info("CSV Import Initializing...");
+ fireOperationInitializing();
+ break;
+ case ABORTED:
+ cancel();
+ Log.info("CSV Import Operation Aborted");
+ break;
+ case IN_PROGRESS:
+ fireOperationUpdate(result.getProgress());
+ break;
+ case FAILED:
+ cancel();
+ Log.info("CSV Import Failed");
+ if (result.getError() != null) {
+ fireOperationFailed(result.getError(),
+ "Failed Client Library Import", result
+ .getError()
+ .getLocalizedMessage());
+ } else {
+ fireOperationFailed(new Throwable("Failed"),
+ "Failed Client Library Import", "CSV Import failed");
+ }
+ break;
+ case SUCCEDED:
+ cancel();
+ Log.info("Import fisnish TableId :"
+ + result.getTrId());
+ fireOperationComplete(result.getTrId());
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ });
- @Override
- public void onFailure(Throwable caught) {
- cancel();
- Log.error("Error retrieving the operation state", caught);
- String message = getStack(caught);
- fireOperationFailed(caught, "Failed getting operation updates", message);
- }
-
- @Override
- public void onSuccess(CSVImportMonitor result) {
- Log.info("retrieved CSVImportMonitor: "+result.getStatus());
- switch (result.getStatus()) {
- case INITIALIZING:
- Log.info("CSV Import Initializing...");
- fireOperationInitializing();
- break;
- case ABORTED:
- cancel();
- Log.info("CSV Import Operation Aborted");
- break;
- case IN_PROGRESS:
- fireOperationUpdate(result.getProgress());
- break;
- case FAILED:
- cancel();
- Log.info("CSV Import Failed");
- fireOperationFailed(result.getError() ,"Failed Client Library Import", result.getError().getLocalizedMessage());
- break;
- case SUCCEDED:
- cancel();
- Log.info("Import fisnish TableId :"+result.getTrId());
- fireOperationComplete(result.getTrId());
- break;
-
- default:
- break;
- }
-
- }
-
-
-
-
-
- });
-
-
-
}
-
- protected String getStack(Throwable e)
- {
- String message = e.getLocalizedMessage()+" ->
";
+
+ protected String getStack(Throwable e) {
+ String message = e.getLocalizedMessage() + " ->
";
Throwable c = e.getCause();
- if (c!=null) message += getStack(c);
+ if (c != null)
+ message += getStack(c);
return message;
}
- protected void fireOperationInitializing()
- {
- for (CSVImportProgressListener listener:listeners) listener.operationInitializing();
- }
-
- protected void fireOperationUpdate(float elaborated)
- {
- for (CSVImportProgressListener listener:listeners) listener.operationUpdate(elaborated);
+ protected void fireOperationInitializing() {
+ for (CSVImportProgressListener listener : listeners)
+ listener.operationInitializing();
}
- protected void fireOperationComplete(TRId trId)
- {
- for (CSVImportProgressListener listener:listeners) listener.operationComplete(trId);
+ protected void fireOperationUpdate(float elaborated) {
+ for (CSVImportProgressListener listener : listeners)
+ listener.operationUpdate(elaborated);
}
-
- protected void fireOperationFailed(Throwable caught, String failure, String failureDetails)
- {
- for (CSVImportProgressListener listener:listeners) listener.operationFailed(caught, failure, failureDetails);
+
+ protected void fireOperationComplete(TRId trId) {
+ for (CSVImportProgressListener listener : listeners)
+ listener.operationComplete(trId);
}
-
+
+ protected void fireOperationFailed(Throwable caught, String failure,
+ String failureDetails) {
+ for (CSVImportProgressListener listener : listeners)
+ listener.operationFailed(caught, failure, failureDetails);
+ }
+
/**
- * Add a new {@link CSVImportProgressListener} to this {@link CSVImportProgressUpdater}.
- * @param listener the listener to add.
+ * Add a new {@link CSVImportProgressListener} to this
+ * {@link CSVImportProgressUpdater}.
+ *
+ * @param listener
+ * the listener to add.
*/
- public void addListener(CSVImportProgressListener listener)
- {
+ public void addListener(CSVImportProgressListener listener) {
listeners.add(listener);
}
/**
- * Removes the specified {@link CSVImportProgressListener} from this {@link CSVImportProgressUpdater}.
- * @param listener the listener to remove.
+ * Removes the specified {@link CSVImportProgressListener} from this
+ * {@link CSVImportProgressUpdater}.
+ *
+ * @param listener
+ * the listener to remove.
*/
- public void removeListener(CSVImportProgressListener listener)
- {
+ public void removeListener(CSVImportProgressListener listener) {
listeners.remove(listener);
}
}