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.TRId;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
|
||||||
|
|
||||||
|
|
||||||
import com.allen_sauer.gwt.log.client.Log;
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This {@link Timer} retrieves {@link OperationProgress} from the specified {@link OperationProgressSource} with the scheduled interval.
|
* This {@link Timer} retrieves {@link OperationProgress} from the specified
|
||||||
* The retrieved information are spread to the subscribed {@link CSVImportProgressListener}.
|
* {@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 {
|
public class CSVImportProgressUpdater extends Timer {
|
||||||
|
|
||||||
protected ArrayList<CSVImportProgressListener> listeners = new ArrayList<CSVImportProgressListener>();
|
protected ArrayList<CSVImportProgressListener> listeners = new ArrayList<CSVImportProgressListener>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.debug("requesting operation progress");
|
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)
|
protected String getStack(Throwable e) {
|
||||||
{
|
String message = e.getLocalizedMessage() + " -> <br>";
|
||||||
String message = e.getLocalizedMessage()+" -> <br>";
|
|
||||||
Throwable c = e.getCause();
|
Throwable c = e.getCause();
|
||||||
if (c!=null) message += getStack(c);
|
if (c != null)
|
||||||
|
message += getStack(c);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireOperationInitializing()
|
protected void fireOperationInitializing() {
|
||||||
{
|
for (CSVImportProgressListener listener : listeners)
|
||||||
for (CSVImportProgressListener listener:listeners) listener.operationInitializing();
|
listener.operationInitializing();
|
||||||
}
|
|
||||||
|
|
||||||
protected void fireOperationUpdate(float elaborated)
|
|
||||||
{
|
|
||||||
for (CSVImportProgressListener listener:listeners) listener.operationUpdate(elaborated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireOperationComplete(TRId trId)
|
protected void fireOperationUpdate(float elaborated) {
|
||||||
{
|
for (CSVImportProgressListener listener : listeners)
|
||||||
for (CSVImportProgressListener listener:listeners) listener.operationComplete(trId);
|
listener.operationUpdate(elaborated);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireOperationFailed(Throwable caught, String failure, String failureDetails)
|
protected void fireOperationComplete(TRId trId) {
|
||||||
{
|
for (CSVImportProgressListener listener : listeners)
|
||||||
for (CSVImportProgressListener listener:listeners) listener.operationFailed(caught, failure, failureDetails);
|
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}.
|
* Add a new {@link CSVImportProgressListener} to this
|
||||||
* @param listener the listener to add.
|
* {@link CSVImportProgressUpdater}.
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener to add.
|
||||||
*/
|
*/
|
||||||
public void addListener(CSVImportProgressListener listener)
|
public void addListener(CSVImportProgressListener listener) {
|
||||||
{
|
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified {@link CSVImportProgressListener} from this {@link CSVImportProgressUpdater}.
|
* Removes the specified {@link CSVImportProgressListener} from this
|
||||||
* @param listener the listener to remove.
|
* {@link CSVImportProgressUpdater}.
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener to remove.
|
||||||
*/
|
*/
|
||||||
public void removeListener(CSVImportProgressListener listener)
|
public void removeListener(CSVImportProgressListener listener) {
|
||||||
{
|
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue