Minor updated
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@84869 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8f7c0ba45f
commit
7ef609383c
|
@ -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" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
* @author "Giancarlo Panichi"
|
||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class CSVImportProgressUpdater extends Timer {
|
||||
|
||||
protected ArrayList<CSVImportProgressListener> listeners = new ArrayList<CSVImportProgressListener>();
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
Log.debug("requesting operation progress");
|
||||
TDGWTServiceAsync.INSTANCE.getCSVImportMonitor(new AsyncCallback<CSVImportMonitor>() {
|
||||
TDGWTServiceAsync.INSTANCE
|
||||
.getCSVImportMonitor(new AsyncCallback<CSVImportMonitor>() {
|
||||
|
||||
@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()+" -> <br>";
|
||||
|
||||
protected String getStack(Throwable e) {
|
||||
String message = e.getLocalizedMessage() + " -> <br>";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue