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:
parent
ca01c0158d
commit
bfba20a1ea
|
@ -49,7 +49,7 @@ public class WorkspaceExplorerListenerController {
|
|||
|
||||
switch(notifyUploadEvent.getEvent()){
|
||||
|
||||
case COMPLETED:
|
||||
case UPLOAD_COMPLETED:
|
||||
GWT.log("NotifyUploadEvent Completed");
|
||||
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
|
||||
break;
|
||||
|
|
|
@ -3,23 +3,19 @@
|
|||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceUploadNotification.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 2, 2015
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 2, 2015
|
||||
*/
|
||||
public class WorkspaceUploadNotification {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The listener interface for receiving worskpaceUploadNotification events.
|
||||
* The class that is interested in processing a worskpaceUploadNotification
|
||||
* event implements this interface, and the object created
|
||||
* with that class is registered with a component using the
|
||||
* component's <code>addWorskpaceUploadNotificationListener<code> method. When
|
||||
* event implements this interface, and the object created with that class
|
||||
* is registered with a component using the component's
|
||||
* <code>addWorskpaceUploadNotificationListener<code> method. When
|
||||
* the worskpaceUploadNotification event occurs, that object's appropriate
|
||||
* method is invoked.
|
||||
*
|
||||
|
@ -30,36 +26,51 @@ public class WorkspaceUploadNotification {
|
|||
/**
|
||||
* On upload completed.
|
||||
*
|
||||
* @param parentID the parent id
|
||||
* @param itemId the item id
|
||||
* @param parentId
|
||||
* the parent id
|
||||
* @param itemId
|
||||
* the item id
|
||||
*/
|
||||
void onUploadCompleted(String parentId, String itemId);
|
||||
|
||||
/**
|
||||
* On upload aborted.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param parentId
|
||||
* the parent id
|
||||
* @param itemId
|
||||
* the item id
|
||||
*/
|
||||
void onUploadAborted(String parentId, String itemId);
|
||||
|
||||
|
||||
/**
|
||||
* On error.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param throwable the throwable
|
||||
* @param parentId
|
||||
* the parent id
|
||||
* @param itemId
|
||||
* the item id
|
||||
* @param throwable
|
||||
* the 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 class that is interested in processing a hasWorskpaceUploadNotification
|
||||
* event implements this interface, and the object created
|
||||
* with that class is registered with a component using the
|
||||
* component's <code>addHasWorskpaceUploadNotificationListener<code> method. When
|
||||
* The listener interface for receiving hasWorskpaceUploadNotification
|
||||
* events. The class that is interested in processing a
|
||||
* hasWorskpaceUploadNotification event implements this interface, and the
|
||||
* object created with that class is registered with a component using the
|
||||
* component's
|
||||
* <code>addHasWorskpaceUploadNotificationListener<code> method. When
|
||||
* the hasWorskpaceUploadNotification event occurs, that object's appropriate
|
||||
* method is invoked.
|
||||
*
|
||||
|
@ -70,17 +81,21 @@ public class WorkspaceUploadNotification {
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param handler the handler
|
||||
* @param handler
|
||||
* the handler
|
||||
*/
|
||||
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler);
|
||||
public void removeWorkspaceUploadNotificationListener(
|
||||
WorskpaceUploadNotificationListener handler);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@ public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
|
|||
* Oct 5, 2015
|
||||
*/
|
||||
public static enum UPLOAD_EVENT_TYPE {
|
||||
COMPLETED, FAILED, ABORTED
|
||||
UPLOAD_COMPLETED, FAILED, ABORTED, OVERWRITE_COMPLETED
|
||||
}
|
||||
|
||||
private UPLOAD_EVENT_TYPE event;
|
||||
|
|
|
@ -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.ui.Anchor;
|
||||
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.FormPanel;
|
||||
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
|
||||
|
@ -155,7 +156,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
|
|||
hpBottom.add(hp2);
|
||||
panel.add(hpBottom);
|
||||
|
||||
add(formPanel);
|
||||
add(formPanel);
|
||||
}
|
||||
|
||||
protected void initJsonClientKeys(){
|
||||
|
@ -357,7 +358,6 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
|
|||
* @param itemId the item id
|
||||
*/
|
||||
protected void updateItemSubmitForm(String itemId){
|
||||
|
||||
hiddenOverwrite.setValue("true");
|
||||
submitForm();
|
||||
}
|
||||
|
|
|
@ -17,15 +17,20 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
|
|||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
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.JSONObject;
|
||||
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.rpc.AsyncCallback;
|
||||
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.SubmitEvent;
|
||||
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;
|
||||
|
||||
|
||||
|
@ -145,6 +150,15 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
removeLoading();
|
||||
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);*/
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -190,8 +190,12 @@ public class UploaderMonitor {
|
|||
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
|
||||
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
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();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
|
@ -223,6 +227,16 @@ public class UploaderMonitor {
|
|||
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.
|
||||
|
@ -232,7 +246,7 @@ public class UploaderMonitor {
|
|||
*/
|
||||
private void notifyUploadCompleted(String parentId, String itemId){
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -343,6 +343,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
WorkspaceUploaderItem workspaceUploader = null;
|
||||
try {
|
||||
workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request.getSession(), clientUploadKey);
|
||||
workspaceUploader.setIsOverwrite(isOverwrite); //SET IS OVERWRITE
|
||||
} catch (Exception 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());
|
||||
|
@ -404,9 +405,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
Long size = getContentLength(request);
|
||||
logger.debug("size: " + size + " bytes");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
String contentType = uploadItem.getContentType();
|
||||
logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName);
|
||||
|
|
|
@ -54,6 +54,7 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
private String statusDescription;
|
||||
private String clientUploadKey;
|
||||
private UploadProgress uploadProgress;
|
||||
private Boolean isOverwrite;
|
||||
// private Long threadId;
|
||||
|
||||
/**
|
||||
|
@ -78,6 +79,7 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
* @param file the file
|
||||
* @param status the status
|
||||
* @param statusDescription the status description
|
||||
* @param uploadProgress the upload progress
|
||||
*/
|
||||
public WorkspaceUploaderItem(String identifier, WorkspaceUploadFile file, UPLOAD_STATUS status, String statusDescription, UploadProgress uploadProgress) {
|
||||
super();
|
||||
|
@ -178,6 +180,8 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the upload progress.
|
||||
*
|
||||
* @return the uploadProgress
|
||||
*/
|
||||
public UploadProgress getUploadProgress() {
|
||||
|
@ -185,25 +189,27 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the upload progress.
|
||||
*
|
||||
* @param uploadProgress the uploadProgress to set
|
||||
*/
|
||||
public void setUploadProgress(UploadProgress uploadProgress) {
|
||||
this.uploadProgress = uploadProgress;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param id
|
||||
// */
|
||||
// public void setThreadId(Long id) {
|
||||
// this.threadId = id;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the threadId
|
||||
// */
|
||||
// public Long getThreadId() {
|
||||
// return threadId;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the isOverwrite
|
||||
*/
|
||||
public Boolean getIsOverwrite() {
|
||||
return isOverwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isOverwrite the isOverwrite to set
|
||||
*/
|
||||
public void setIsOverwrite(Boolean isOverwrite) {
|
||||
this.isOverwrite = isOverwrite;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
|
@ -223,6 +229,8 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
builder.append(clientUploadKey);
|
||||
builder.append(", uploadProgress=");
|
||||
builder.append(uploadProgress);
|
||||
builder.append(", isOverwrite=");
|
||||
builder.append(isOverwrite);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue