429: Workspace: uploading big files

Task-Url: https://support.d4science.org/issues/429

Added case overwrite into listener

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@119823 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-10-16 09:00:36 +00:00
parent ca01c0158d
commit bfba20a1ea
8 changed files with 186 additions and 49 deletions

View File

@ -49,7 +49,7 @@ public class WorkspaceExplorerListenerController {
switch(notifyUploadEvent.getEvent()){ switch(notifyUploadEvent.getEvent()){
case COMPLETED: case UPLOAD_COMPLETED:
GWT.log("NotifyUploadEvent Completed"); GWT.log("NotifyUploadEvent Completed");
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId()); notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
break; break;

View File

@ -3,23 +3,19 @@
*/ */
package org.gcube.portlets.widgets.workspaceuploader.client; package org.gcube.portlets.widgets.workspaceuploader.client;
/** /**
* The Class WorkspaceUploadNotification. * The Class WorkspaceUploadNotification.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 2, 2015
* Oct 2, 2015
*/ */
public class WorkspaceUploadNotification { public class WorkspaceUploadNotification {
/** /**
* The listener interface for receiving worskpaceUploadNotification events. * The listener interface for receiving worskpaceUploadNotification events.
* The class that is interested in processing a worskpaceUploadNotification * The class that is interested in processing a worskpaceUploadNotification
* event implements this interface, and the object created * event implements this interface, and the object created with that class
* with that class is registered with a component using the * is registered with a component using the component's
* component's <code>addWorskpaceUploadNotificationListener<code> method. When * <code>addWorskpaceUploadNotificationListener<code> method. When
* the worskpaceUploadNotification event occurs, that object's appropriate * the worskpaceUploadNotification event occurs, that object's appropriate
* method is invoked. * method is invoked.
* *
@ -30,36 +26,51 @@ public class WorkspaceUploadNotification {
/** /**
* On upload completed. * On upload completed.
* *
* @param parentID the parent id * @param parentId
* @param itemId the item id * the parent id
* @param itemId
* the item id
*/ */
void onUploadCompleted(String parentId, String itemId); void onUploadCompleted(String parentId, String itemId);
/** /**
* On upload aborted. * On upload aborted.
* *
* @param parentId the parent id * @param parentId
* @param itemId the item id * the parent id
* @param itemId
* the item id
*/ */
void onUploadAborted(String parentId, String itemId); void onUploadAborted(String parentId, String itemId);
/** /**
* On error. * On error.
* *
* @param parentId the parent id * @param parentId
* @param itemId the item id * the parent id
* @param throwable the throwable * @param itemId
* the item id
* @param throwable
* the throwable
*/ */
void onError(String parentId, String itemId, Throwable throwable); void onError(String parentId, String itemId, Throwable throwable);
/**
* On overwrite completed.
*
* @param parentId the parent id
* @param itemId the item id
*/
void onOverwriteCompleted(String parentId, String itemId);
} }
/** /**
* The listener interface for receiving hasWorskpaceUploadNotification events. * The listener interface for receiving hasWorskpaceUploadNotification
* The class that is interested in processing a hasWorskpaceUploadNotification * events. The class that is interested in processing a
* event implements this interface, and the object created * hasWorskpaceUploadNotification event implements this interface, and the
* with that class is registered with a component using the * object created with that class is registered with a component using the
* component's <code>addHasWorskpaceUploadNotificationListener<code> method. When * component's
* <code>addHasWorskpaceUploadNotificationListener<code> method. When
* the hasWorskpaceUploadNotification event occurs, that object's appropriate * the hasWorskpaceUploadNotification event occurs, that object's appropriate
* method is invoked. * method is invoked.
* *
@ -70,17 +81,21 @@ public class WorkspaceUploadNotification {
/** /**
* Adds the workspace upload notification listener. * Adds the workspace upload notification listener.
* *
* @param handler the handler * @param handler
* the handler
*/ */
public void addWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler); public void addWorkspaceUploadNotificationListener(
WorskpaceUploadNotificationListener handler);
/** /**
* Removes the workspace upload notification listener. * Removes the workspace upload notification listener.
* *
* @param handler the handler * @param handler
* the handler
*/ */
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler); public void removeWorkspaceUploadNotificationListener(
WorskpaceUploadNotificationListener handler);
} }
} }

View File

@ -19,7 +19,7 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
* Oct 5, 2015 * Oct 5, 2015
*/ */
public static enum UPLOAD_EVENT_TYPE { public static enum UPLOAD_EVENT_TYPE {
COMPLETED, FAILED, ABORTED UPLOAD_COMPLETED, FAILED, ABORTED, OVERWRITE_COMPLETED
} }
private UPLOAD_EVENT_TYPE event; private UPLOAD_EVENT_TYPE event;

View File

@ -24,6 +24,7 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FileUpload; import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel; import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent; import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
@ -155,7 +156,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
hpBottom.add(hp2); hpBottom.add(hp2);
panel.add(hpBottom); panel.add(hpBottom);
add(formPanel); add(formPanel);
} }
protected void initJsonClientKeys(){ protected void initJsonClientKeys(){
@ -357,7 +358,6 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
* @param itemId the item id * @param itemId the item id
*/ */
protected void updateItemSubmitForm(String itemId){ protected void updateItemSubmitForm(String itemId){
hiddenOverwrite.setValue("true"); hiddenOverwrite.setValue("true");
submitForm(); submitForm();
} }

View File

@ -17,15 +17,20 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString; import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent; import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler; import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent; import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler; import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
@ -145,6 +150,15 @@ public class MultipleDilaogUpload extends DialogUpload {
removeLoading(); removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem); UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
} }
/*new Timer() {
@Override
public void run() {
stopIFrame(formPanel.getTarget());
}
}.schedule(500);*/
} }
}); });
@ -273,7 +287,94 @@ public class MultipleDilaogUpload extends DialogUpload {
// }.schedule(100);*/ // }.schedule(100);*/
// } // }
} }
private void showCancel(){
DialogBox box = new DialogBox();
box.setSize("200px","200px");
Button abort = new Button("abort");
abort.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String iFrameName = formPanel.getTarget();
GWT.log("iFrameName "+iFrameName);
stopIFrame(iFrameName);
}
});
box.add(abort);
box.show();
// box.hide(true);
/*
if (iframeObj.contentWindow.document.execCommand)
{ // IE browsers
iframeObj.contentWindow.document.execCommand("Stop");
}
else
{ // other browsers
iframeObj.contentWindow.stop();
}
// notify user upload was cancelled, remove spinner images, etc*/
}
/**
* Gets the files selected.
*
* @param tagId the tag id
* @param fileDelimiter the file delimiter
* @return the files selected
*/
public static native String stopIFrame(final String iFrameName) /*-{
console.log("iFrameName: "+iFrameName);
// var iframe= window.frames[iFrameName];
var iframe= window.frames["'"+iFrameName+"'"];
if(iframe==null){
console.log("iframe is null");
return;
}else
console.log("iframe is not null");
if (navigator.appName == 'Microsoft Internet Explorer') {
iframe.document.execCommand('Stop');
} else {
iframe.stop();
}
// var iframe= $wnd.$('iframe[name='+iFrameName+']', parent.document)[0];
// var iframewindow= iframe.contentWindow? iframe.contentWindow : iframe.contentDocument.defaultView;
// if(iframe==null)
// console.log("iframe is null");
// else
// console.log("iframe is not null");
//
// if (navigator.appName == 'Microsoft Internet Explorer' && iframewindow.document.execCommand)
// { // IE browsers
// console.log("IE browsers");
// iframewindow.document.execCommand("Stop");
// }
// else
// { // other browsers
// console.log("other browsers");
// iframewindow.stop();
// }
}-*/;
// var iframewindow= iframe.contentWindow? iframe.contentWindow : iframe.contentDocument.defaultView;
//
// iframewindow.stop();
// iframe.remove();
//
// if (iframewindow.document.execCommand)
// { // IE browsers
// console.log("IE browsers");
// iframewindow.document.execCommand("Stop");
// }
// else
// { // other browsers
// console.log("other browsers");
// iframewindow.stop();
// }
/** /**
* Gets the files selected. * Gets the files selected.
* *

View File

@ -190,8 +190,12 @@ public class UploaderMonitor {
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){ if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName()); GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
mapTimer.remove(tmn); mapTimer.remove(tmn);
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
// new DialogResult(null, "Upload Completed!!", result.getStatusDescription()).center(); if(!result.getIsOverwrite())
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
else
notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
cancel(); cancel();
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){ }else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName()); GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
@ -223,6 +227,16 @@ public class UploaderMonitor {
timer.scheduleRepeating(2000); timer.scheduleRepeating(2000);
} }
/**
* Notify upload completed.
*
* @param parentId the parent id
* @param itemId the item id
*/
private void notifyOverwriteCompleted(String parentId, String itemId){
GWT.log("notifyOverwriteCompleted in monitor");
WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
}
/** /**
* Notify upload completed. * Notify upload completed.
@ -232,7 +246,7 @@ public class UploaderMonitor {
*/ */
private void notifyUploadCompleted(String parentId, String itemId){ private void notifyUploadCompleted(String parentId, String itemId){
GWT.log("notifyUploadCompleted in monitor"); GWT.log("notifyUploadCompleted in monitor");
WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.COMPLETED, parentId, itemId)); WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
} }
/** /**

View File

@ -343,6 +343,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
WorkspaceUploaderItem workspaceUploader = null; WorkspaceUploaderItem workspaceUploader = null;
try { try {
workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request.getSession(), clientUploadKey); workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request.getSession(), clientUploadKey);
workspaceUploader.setIsOverwrite(isOverwrite); //SET IS OVERWRITE
} catch (Exception e) { } catch (Exception e) {
logger.error("Error during workspace uploader retrieving", e); logger.error("Error during workspace uploader retrieving", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession()); saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession());
@ -404,9 +405,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
Long size = getContentLength(request); Long size = getContentLength(request);
logger.debug("size: " + size + " bytes"); logger.debug("size: " + size + " bytes");
/* /*
String contentType = uploadItem.getContentType(); String contentType = uploadItem.getContentType();
logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName); logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName);

View File

@ -54,6 +54,7 @@ public class WorkspaceUploaderItem implements Serializable{
private String statusDescription; private String statusDescription;
private String clientUploadKey; private String clientUploadKey;
private UploadProgress uploadProgress; private UploadProgress uploadProgress;
private Boolean isOverwrite;
// private Long threadId; // private Long threadId;
/** /**
@ -78,6 +79,7 @@ public class WorkspaceUploaderItem implements Serializable{
* @param file the file * @param file the file
* @param status the status * @param status the status
* @param statusDescription the status description * @param statusDescription the status description
* @param uploadProgress the upload progress
*/ */
public WorkspaceUploaderItem(String identifier, WorkspaceUploadFile file, UPLOAD_STATUS status, String statusDescription, UploadProgress uploadProgress) { public WorkspaceUploaderItem(String identifier, WorkspaceUploadFile file, UPLOAD_STATUS status, String statusDescription, UploadProgress uploadProgress) {
super(); super();
@ -178,6 +180,8 @@ public class WorkspaceUploaderItem implements Serializable{
} }
/** /**
* Gets the upload progress.
*
* @return the uploadProgress * @return the uploadProgress
*/ */
public UploadProgress getUploadProgress() { public UploadProgress getUploadProgress() {
@ -185,25 +189,27 @@ public class WorkspaceUploaderItem implements Serializable{
} }
/** /**
* Sets the upload progress.
*
* @param uploadProgress the uploadProgress to set * @param uploadProgress the uploadProgress to set
*/ */
public void setUploadProgress(UploadProgress uploadProgress) { public void setUploadProgress(UploadProgress uploadProgress) {
this.uploadProgress = uploadProgress; this.uploadProgress = uploadProgress;
} }
// /** /**
// * @param id * @return the isOverwrite
// */ */
// public void setThreadId(Long id) { public Boolean getIsOverwrite() {
// this.threadId = id; return isOverwrite;
// } }
//
// /** /**
// * @return the threadId * @param isOverwrite the isOverwrite to set
// */ */
// public Long getThreadId() { public void setIsOverwrite(Boolean isOverwrite) {
// return threadId; this.isOverwrite = isOverwrite;
// } }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
@ -223,6 +229,8 @@ public class WorkspaceUploaderItem implements Serializable{
builder.append(clientUploadKey); builder.append(clientUploadKey);
builder.append(", uploadProgress="); builder.append(", uploadProgress=");
builder.append(uploadProgress); builder.append(uploadProgress);
builder.append(", isOverwrite=");
builder.append(isOverwrite);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }