Propagated error case to improve error messages client-side

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@142309 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-07 10:14:30 +00:00
parent 938d9ace9c
commit d23603d024
5 changed files with 82 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.workspaceuploader.client; package org.gcube.portlets.widgets.workspaceuploader.client;
@ -23,9 +23,9 @@ import com.google.gwt.event.shared.HandlerManager;
public class WorkspaceUploaderListenerController { public class WorkspaceUploaderListenerController {
private static HandlerManager controllerEventBus = null; private static HandlerManager controllerEventBus = null;
private List<WorskpaceUploadNotificationListener> listenersUpload = new ArrayList<WorskpaceUploadNotificationListener>(); private List<WorskpaceUploadNotificationListener> listenersUpload = new ArrayList<WorskpaceUploadNotificationListener>();
/** /**
* Instantiates a new workspace explorer listener controller. * Instantiates a new workspace explorer listener controller.
*/ */
@ -34,21 +34,21 @@ public class WorkspaceUploaderListenerController {
bindEvents(); bindEvents();
} }
/** /**
* Bind events. * Bind events.
*/ */
private void bindEvents() { private void bindEvents() {
controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() { controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() {
@Override @Override
public void onNotifyUpload(NotifyUploadEvent notifyUploadEvent) { public void onNotifyUpload(NotifyUploadEvent notifyUploadEvent) {
if(notifyUploadEvent.getEvent()==null) if(notifyUploadEvent.getEvent()==null)
return; return;
switch(notifyUploadEvent.getEvent()){ switch(notifyUploadEvent.getEvent()){
case UPLOAD_COMPLETED: case UPLOAD_COMPLETED:
GWT.log("NotifyUploadEvent Completed"); GWT.log("NotifyUploadEvent Completed");
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId()); notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
@ -59,7 +59,7 @@ public class WorkspaceUploaderListenerController {
break; break;
case FAILED: case FAILED:
GWT.log("NotifyUploadEvent FAILED"); GWT.log("NotifyUploadEvent FAILED");
notifyUploadError(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId(), notifyUploadEvent.getException()); notifyUploadError(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId(), new Exception(notifyUploadEvent.getUploadResultMsg()));
break; break;
case OVERWRITE_COMPLETED: case OVERWRITE_COMPLETED:
GWT.log("NotifyUploadEvent OVERWRITE_COMPLETED"); GWT.log("NotifyUploadEvent OVERWRITE_COMPLETED");
@ -67,7 +67,7 @@ public class WorkspaceUploaderListenerController {
break; break;
default: default:
break; break;
} }
} }
}); });
@ -103,14 +103,14 @@ public class WorkspaceUploaderListenerController {
// SILENT // SILENT
} }
} }
/** /**
* Reset listeners. * Reset listeners.
*/ */
public void resetListeners(){ public void resetListeners(){
this.listenersUpload.clear(); this.listenersUpload.clear();
} }
/** /**
* Notify upload completed. * Notify upload completed.
* *
@ -123,7 +123,7 @@ public class WorkspaceUploaderListenerController {
listener.onUploadCompleted(parentId, itemId); listener.onUploadCompleted(parentId, itemId);
} }
} }
/** /**
* Notify overwrite completed. * Notify overwrite completed.
* *
@ -136,7 +136,7 @@ public class WorkspaceUploaderListenerController {
listener.onOverwriteCompleted(parentId, itemId); listener.onOverwriteCompleted(parentId, itemId);
} }
} }
/** /**
* Notify upload aborted. * Notify upload aborted.
* *
@ -148,7 +148,7 @@ public class WorkspaceUploaderListenerController {
listener.onUploadAborted(parentId, itemId); listener.onUploadAborted(parentId, itemId);
} }
} }
/** /**
* Notify upload error. * Notify upload error.
* *
@ -161,7 +161,7 @@ public class WorkspaceUploaderListenerController {
listener.onError(parentId, itemId, t); listener.onError(parentId, itemId, t);
} }
} }
/** /**
* Listeners size. * Listeners size.
* *

View File

@ -25,10 +25,13 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
private UPLOAD_EVENT_TYPE event; private UPLOAD_EVENT_TYPE event;
private String parentId; private String parentId;
private String itemId; private String itemId;
private String uploadResultMsg;
private Throwable exception; private Throwable exception;
/** /**
* Gets the exception.
*
* @return the exception * @return the exception
*/ */
public Throwable getException() { public Throwable getException() {
@ -36,6 +39,8 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Sets the exception.
*
* @param exception the exception to set * @param exception the exception to set
*/ */
public void setException(Throwable exception) { public void setException(Throwable exception) {
@ -43,6 +48,8 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Gets the event.
*
* @return the event * @return the event
*/ */
public UPLOAD_EVENT_TYPE getEvent() { public UPLOAD_EVENT_TYPE getEvent() {
@ -50,6 +57,8 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Sets the event.
*
* @param event the event to set * @param event the event to set
*/ */
public void setEvent(UPLOAD_EVENT_TYPE event) { public void setEvent(UPLOAD_EVENT_TYPE event) {
@ -58,15 +67,24 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
/** /**
* Instantiates a new notify upload event. * Instantiates a new notify upload event.
*
* @param event the event
* @param parentId the parent id
* @param itemId the item id
*/ */
public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId) { public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId) {
this.parentId = parentId; this.parentId = parentId;
this.itemId = itemId; this.itemId = itemId;
this.event = event; this.event = event;
} }
/** /**
* Instantiates a new notify upload event. * Instantiates a new notify upload event.
*
* @param event the event
* @param parentId the parent id
* @param itemId the item id
* @param e the e
*/ */
public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, Throwable e) { public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, Throwable e) {
this.parentId = parentId; this.parentId = parentId;
@ -75,7 +93,27 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
this.exception = e; this.exception = e;
} }
/** /**
* Instantiates a new notify upload event.
*
* @param event the event
* @param parentId the parent id
* @param itemId the item id
* @param uploadResultMsg the upload result msg
* @param e the e
*/
public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, String uploadResultMsg, Throwable e) {
this.parentId = parentId;
this.itemId = itemId;
this.event = event;
this.uploadResultMsg = uploadResultMsg;
this.exception = e;
}
/**
* Gets the parent id.
*
* @return the parentId * @return the parentId
*/ */
public String getParentId() { public String getParentId() {
@ -83,6 +121,8 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Gets the item id.
*
* @return the itemId * @return the itemId
*/ */
public String getItemId() { public String getItemId() {
@ -90,6 +130,8 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Sets the parent id.
*
* @param parentId the parentId to set * @param parentId the parentId to set
*/ */
public void setParentId(String parentId) { public void setParentId(String parentId) {
@ -97,15 +139,27 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
} }
/** /**
* Sets the item id.
*
* @param itemId the itemId to set * @param itemId the itemId to set
*/ */
public void setItemId(String itemId) { public void setItemId(String itemId) {
this.itemId = itemId; this.itemId = itemId;
} }
/**
* @return the uploadResultMsg
*/
public String getUploadResultMsg() {
return uploadResultMsg;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/ */
@Override @Override
@ -115,7 +169,7 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see * @see
* com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared
* .EventHandler) * .EventHandler)

View File

@ -71,7 +71,7 @@ public class TimerUpload extends Timer{
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName()); GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey()); // monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
// queue.remove(workspaceUploader.getClientUploadKey()); // queue.remove(workspaceUploader.getClientUploadKey());
monitor.notifyUploadError(result.getFile().getParentId(), null, null); monitor.notifyUploadError(result.getFile().getParentId(), null, result.getStatusDescription(), null);
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center(); // new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
cancel(); cancel();
@ -80,6 +80,7 @@ public class TimerUpload extends Timer{
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey()); // monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
GWT.log("Upload Aborted "+result.getFile().getItemId() +" name: "+result.getFile().getFileName()); GWT.log("Upload Aborted "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
cancel(); cancel();
monitor.notifyUploadAborted(result.getFile().getParentId(), null);
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey()); monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
} }
@ -103,7 +104,7 @@ public class TimerUpload extends Timer{
cancel(); cancel();
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey()); // monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey()); monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
monitor.notifyUploadError(workspaceUploader.getFile().getParentId(), null, caught); monitor.notifyUploadError(workspaceUploader.getFile().getParentId(), null, null, caught);
// removeTimer(workspaceUploader.getClientUploadKey()); // removeTimer(workspaceUploader.getClientUploadKey());
} }
}); });

View File

@ -299,8 +299,8 @@ public class UploaderMonitor {
* @param itemId the item id * @param itemId the item id
* @param t the t * @param t the t
*/ */
protected void notifyUploadError(String parentId, String itemId, Throwable t){ protected void notifyUploadError(String parentId, String itemId, String error, Throwable t){
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t)); WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, error, t));
} }

View File

@ -101,11 +101,10 @@ public class WorkspaceUploaderMng {
} catch (Exception e1) { } catch (Exception e1) {
logger.error("Error during WorkspaceUploaderItem session update: ",e1); logger.error("Error during WorkspaceUploaderItem session update: ",e1);
} }
} catch (InsufficientPrivilegesException } catch (InternalErrorException
| ItemAlreadyExistException | InternalErrorException
| IOException e) { | IOException e) {
logger.error("Error during upload: ",e); logger.error("Error during upload: ",e);
workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage()); workspaceUploader.setStatusDescription("An error occurred server-side during upload: "+itemName+". "+e.getMessage() +". Try again");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
try { try {
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader); WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
@ -113,7 +112,7 @@ public class WorkspaceUploaderMng {
logger.error("Error during WorkspaceUploaderItem session update: ",e1); logger.error("Error during WorkspaceUploaderItem session update: ",e1);
} }
} catch (ItemNotFoundException | WrongItemTypeException | WorkspaceFolderNotFoundException | WrongDestinationException e) { } catch (InsufficientPrivilegesException| ItemAlreadyExistException | ItemNotFoundException | WrongItemTypeException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
logger.error("Error during overwrite: ",e); logger.error("Error during overwrite: ",e);
workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage()); workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);