429: Workspace: uploading big files
Task-Url: https://support.d4science.org/issues/429 Added listeners to notify upload status git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@119348 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
50435c4f8f
commit
98f8bcb2d6
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceUploadNotification.
|
||||
*
|
||||
* @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
|
||||
* the worskpaceUploadNotification event occurs, that object's appropriate
|
||||
* method is invoked.
|
||||
*
|
||||
* @see WorskpaceUploadNotificationEvent
|
||||
*/
|
||||
public interface WorskpaceUploadNotificationListener {
|
||||
|
||||
/**
|
||||
* On upload completed.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
void onUploadAborted(String parentId, String itemId);
|
||||
|
||||
|
||||
/**
|
||||
* On error.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param throwable the throwable
|
||||
*/
|
||||
void onError(String parentId, String itemId, Throwable throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @see HasWorskpaceUploadNotificationEvent
|
||||
*/
|
||||
public interface HasWorskpaceUploadNotificationListener {
|
||||
|
||||
/**
|
||||
* Adds the workspace upload notification listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void addWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler);
|
||||
|
||||
/**
|
||||
* Removes the workspace upload notification listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package org.gcube.portlets.widgets.workspaceuploader.client;
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUploadStream;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
|
@ -68,14 +66,14 @@ public class WorkspaceUploader implements EntryPoint {
|
|||
});
|
||||
|
||||
|
||||
buttonUploader.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
DialogUpload uploader = new DialogUpload(headerTitle, parentId, UPLOAD_TYPE.File);
|
||||
uploader.center();
|
||||
}
|
||||
});
|
||||
// buttonUploader.addClickHandler(new ClickHandler() {
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(ClickEvent event) {
|
||||
// DialogUpload uploader = new DialogUpload(headerTitle, parentId, UPLOAD_TYPE.File);
|
||||
// uploader.center();
|
||||
// }
|
||||
// });
|
||||
|
||||
buttonDirect.addClickHandler(new ClickHandler() {
|
||||
|
||||
|
|
|
@ -1,347 +0,0 @@
|
|||
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
|
||||
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
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;
|
||||
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.HTML;
|
||||
import com.google.gwt.user.client.ui.Hidden;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
|
||||
/**
|
||||
* The Class DialogUpload.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 24, 2015
|
||||
*/
|
||||
public class DialogUpload extends DialogBox {
|
||||
|
||||
private final FormPanel formPanel = new FormPanel();
|
||||
private boolean isStatusCompleted = false;
|
||||
private Button btnSubmit = new Button("Upload");
|
||||
private Button btnCancel = new Button("Cancel");
|
||||
private Hidden hiddenOverwrite = new Hidden(ConstantsWorkspaceUploader.IS_OVERWRITE,"false");
|
||||
private FileUpload upload;
|
||||
|
||||
/**
|
||||
* The Enum UPLOAD_TYPE.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 24, 2015
|
||||
*/
|
||||
public static enum UPLOAD_TYPE {File, Archive};
|
||||
private HTML LOADING = new HTML("Upload starting...");
|
||||
|
||||
private String parentIdentifier = "";
|
||||
private VerticalPanel panel;
|
||||
private HorizontalPanel hpButtons;
|
||||
private String clientUploadKey;
|
||||
|
||||
/**
|
||||
* Instantiates a new dialog upload.
|
||||
*
|
||||
* @param headerTitle the header title
|
||||
* @param parentId the parent id
|
||||
* @param uploadType the upload type
|
||||
*/
|
||||
public DialogUpload(String headerTitle, final String parentId, UPLOAD_TYPE uploadType){
|
||||
|
||||
setText(headerTitle);
|
||||
this.parentIdentifier = parentId;
|
||||
formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET);
|
||||
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
|
||||
formPanel.setMethod(FormPanel.METHOD_POST);
|
||||
formPanel.setWidth("auto");
|
||||
|
||||
// Create a panel to hold all of the form widgets.
|
||||
panel = new VerticalPanel();
|
||||
formPanel.setWidget(panel);
|
||||
setModal(false);
|
||||
|
||||
upload = new FileUpload();
|
||||
upload.setName(ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT);
|
||||
|
||||
// Add hidden parameters
|
||||
panel.add(new Hidden(ConstantsWorkspaceUploader.ID_FOLDER,parentId));
|
||||
panel.add(new Hidden(ConstantsWorkspaceUploader.UPLOAD_TYPE,uploadType.toString()));
|
||||
panel.add(hiddenOverwrite);
|
||||
clientUploadKey = GenerateUUID.get(15, 16);
|
||||
panel.add(new Hidden(ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS,clientUploadKey));
|
||||
panel.add(upload);
|
||||
hpButtons = new HorizontalPanel();
|
||||
hpButtons.getElement().getStyle().setMarginTop(10, Unit.PX);
|
||||
hpButtons.getElement().getStyle().setMarginBottom(10, Unit.PX);
|
||||
btnCancel.getElement().getStyle().setMarginLeft(10, Unit.PX);
|
||||
hpButtons.add(btnSubmit);
|
||||
hpButtons.add(btnCancel);
|
||||
panel.add(hpButtons);
|
||||
|
||||
// handle the post
|
||||
formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {
|
||||
|
||||
@Override
|
||||
public void onSubmitComplete(SubmitCompleteEvent event) {
|
||||
GWT.log("onSubmitComplete");
|
||||
hide();
|
||||
isStatusCompleted = true;
|
||||
String result = event.getResults();
|
||||
|
||||
if (result == null) {
|
||||
removeLoading();
|
||||
new DialogResult(null, "Error during upload", "An error occurred during file upload.").center();
|
||||
return;
|
||||
}
|
||||
String strippedResult = new HTML(result).getText();
|
||||
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
|
||||
|
||||
switch (resultMessage.getStatus()) {
|
||||
case ERROR:
|
||||
removeLoading();
|
||||
GWT.log("Error during upload "+resultMessage.getMessage());
|
||||
break;
|
||||
case UNKNOWN:
|
||||
removeLoading();
|
||||
GWT.log("Error during upload "+resultMessage.getMessage());
|
||||
break;
|
||||
case WARN: {
|
||||
GWT.log("Upload completed with warnings "+resultMessage.getMessage());
|
||||
removeLoading();
|
||||
break;
|
||||
}
|
||||
case OK: {
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
|
||||
|
||||
/*Timer t = new Timer() {
|
||||
public void run() {
|
||||
GWT.log("Upload started with id: "+resultMessage.getMessage());
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
t.schedule(250);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
formPanel.addSubmitHandler(new SubmitHandler() {
|
||||
|
||||
@Override
|
||||
public void onSubmit(SubmitEvent event) {
|
||||
GWT.log("SubmitEvent");
|
||||
addLoading();
|
||||
enableButtons(false);
|
||||
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem(clientUploadKey);
|
||||
fakeUploader.setClientUploadKey(clientUploadKey);
|
||||
UploaderMonitor.getInstance().addNewSubmit(fakeUploader, upload.getFilename());
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
add(formPanel);
|
||||
|
||||
this.addListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the loading.
|
||||
*/
|
||||
private void addLoading(){
|
||||
panel.add(LOADING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the loading.
|
||||
*/
|
||||
private void removeLoading(){
|
||||
try{
|
||||
panel.remove(LOADING);
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable buttons.
|
||||
*
|
||||
* @param bool the bool
|
||||
*/
|
||||
private void enableButtons(boolean bool){
|
||||
btnSubmit.setEnabled(bool);
|
||||
btnCancel.setEnabled(bool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the listeners.
|
||||
*/
|
||||
private void addListeners() {
|
||||
|
||||
btnSubmit.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
GWT.log("btnSubmit click");
|
||||
if (upload.getFilename()==null || !(upload.getFilename().length()>2)) {
|
||||
GWT.log("No file specified ");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
|
||||
*/
|
||||
String normalizedFileName = upload.getFilename();
|
||||
if (normalizedFileName.contains("\\")) {
|
||||
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
|
||||
}
|
||||
final String label = normalizedFileName;
|
||||
WorkspaceUploaderServiceAsync.Util.getInstance().itemExistsInWorkpaceFolder(parentIdentifier, normalizedFileName, new AsyncCallback<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final String itemId) {
|
||||
GWT.log("itemExistsInWorkpaceFolder: "+itemId);
|
||||
//TODO HANDLE OWERWRITE
|
||||
|
||||
// if(itemId!=null){
|
||||
//
|
||||
// MessageBoxConfirm msg = new MessageBoxConfirm("Replace "+label+"?", label + " exists in folder "+parentName + ". Overwrite?");
|
||||
//
|
||||
//
|
||||
// msg.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||
//
|
||||
// public void handleEvent(MessageBoxEvent be) {
|
||||
//
|
||||
// //IF NOT CANCELLED
|
||||
// String clickedButton = be.getButtonClicked().getItemId();
|
||||
//
|
||||
// if(clickedButton.equals(Dialog.YES)){
|
||||
//
|
||||
//// removeItemAndSubmitForm(itemId);
|
||||
// updateItemSubmitForm(itemId);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }else
|
||||
|
||||
submitForm(); //ITEM does NOT EXIST SO SUBMIT FORM;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log("Sorry an error occurred on the server "+caught.getLocalizedMessage() + ". Please try again later");
|
||||
Window.alert(caught.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
hide();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Submit form.
|
||||
*/
|
||||
public void submitForm(){
|
||||
|
||||
/*messageBoxWait = new MessageBoxWait(ConstantsExplorer.PROGRESS, ConstantsExplorer.SAVINGYOURFILE, fileUploadField.getValue());
|
||||
|
||||
//Progress bar for upload
|
||||
final Timer t = new Timer()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (isStatusCompleted)
|
||||
{
|
||||
cancel();
|
||||
messageBoxWait.getMessageBoxWait().close();
|
||||
}
|
||||
}
|
||||
};
|
||||
t.scheduleRepeating(500);*/
|
||||
GWT.log("Form submit: "+formPanel.getAction());
|
||||
formPanel.submit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the item and submit form.
|
||||
*
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private void removeItemAndSubmitForm(String itemId){
|
||||
/*
|
||||
AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
Info.display("Error", caught.getMessage());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
if(result){
|
||||
hiddenOverwrite.setValue("true");
|
||||
submitForm();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update item submit form.
|
||||
*
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private void updateItemSubmitForm(String itemId){
|
||||
|
||||
hiddenOverwrite.setValue("true");
|
||||
submitForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is status completed.
|
||||
*
|
||||
* @return the isStatusCompleted
|
||||
*/
|
||||
public boolean isStatusCompleted() {
|
||||
return isStatusCompleted;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||
|
@ -15,7 +17,6 @@ import com.google.gwt.core.client.GWT;
|
|||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
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.Anchor;
|
||||
|
@ -40,12 +41,11 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 24, 2015
|
||||
*/
|
||||
public class DialogUploadStream extends ClosableDialog {
|
||||
public class DialogUploadStream extends ClosableDialog implements HasWorskpaceUploadNotificationListener{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
private DialogUploadStream INSTANCE = this;
|
||||
// private boolean isStatusCompleted = false;
|
||||
protected Button btnUpload = new Button("Upload");
|
||||
|
@ -214,18 +214,18 @@ public class DialogUploadStream extends ClosableDialog {
|
|||
UploaderMonitor.getInstance().addNewSubmit(fakeUploader, fileUpload.getFilename());
|
||||
setVisible(false);
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploaderId(clientUploadKey);
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
|
||||
|
||||
//WAITING 0.5 SEC TO FIRST UPDATES
|
||||
new Timer() {
|
||||
/*new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploaderId(clientUploadKey);
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
|
||||
|
||||
}
|
||||
}.schedule(500);
|
||||
}.schedule(500);*/
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -308,15 +308,6 @@ public class DialogUploadStream extends ClosableDialog {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
// btnCancel.addClickHandler(new ClickHandler() {
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(ClickEvent event) {
|
||||
// hide();
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
@ -324,22 +315,6 @@ public class DialogUploadStream extends ClosableDialog {
|
|||
* Submit form.
|
||||
*/
|
||||
public void submitForm(){
|
||||
|
||||
/*messageBoxWait = new MessageBoxWait(ConstantsExplorer.PROGRESS, ConstantsExplorer.SAVINGYOURFILE, fileUploadField.getValue());
|
||||
|
||||
//Progress bar for upload
|
||||
final Timer t = new Timer()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (isStatusCompleted)
|
||||
{
|
||||
cancel();
|
||||
messageBoxWait.getMessageBoxWait().close();
|
||||
}
|
||||
}
|
||||
};
|
||||
t.scheduleRepeating(500);*/
|
||||
formPanel.submit();
|
||||
}
|
||||
|
||||
|
@ -382,5 +357,21 @@ public class DialogUploadStream extends ClosableDialog {
|
|||
hiddenOverwrite.setValue("true");
|
||||
submitForm();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#addWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
|
||||
*/
|
||||
@Override
|
||||
public void addWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
|
||||
UploaderMonitor.getInstance().addWorkspaceUploadListener(handler);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#removeWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
|
||||
UploaderMonitor.getInstance().removeWorkspaceUploadListener(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploadFile;
|
||||
|
@ -28,13 +29,14 @@ 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.HTML;
|
||||
|
||||
|
||||
/**
|
||||
* The Class MultipleDilaogUploadStream.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 11, 2015
|
||||
* Oct 2, 2015
|
||||
*/
|
||||
public class MultipleDilaogUploadStream extends DialogUploadStream{
|
||||
public class MultipleDilaogUploadStream extends DialogUploadStream {
|
||||
|
||||
|
||||
private static final String FILE_DELEMITER = ";";
|
||||
|
@ -147,8 +149,8 @@ public class MultipleDilaogUploadStream extends DialogUploadStream{
|
|||
/**
|
||||
* Generate new upload client keys.
|
||||
*
|
||||
* @param nmb the nmb
|
||||
* @return
|
||||
* @param files the files
|
||||
* @param parentId the parent id
|
||||
*/
|
||||
private void generateFakeUploaders(String[] files, String parentId){
|
||||
|
||||
|
@ -234,7 +236,7 @@ public class MultipleDilaogUploadStream extends DialogUploadStream{
|
|||
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||
setVisible(false);
|
||||
removeLoading();
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
|
||||
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||
|
||||
//WAITING 0.1 SEC TO FIRST UPDATES
|
||||
/*new Timer() {
|
||||
|
@ -254,8 +256,7 @@ public class MultipleDilaogUploadStream extends DialogUploadStream{
|
|||
/**
|
||||
* Creates the json key for files.
|
||||
*
|
||||
* @param files the files
|
||||
* @param currentClientKeys
|
||||
* @param fakeFiles the fake files
|
||||
* @return the string
|
||||
*/
|
||||
protected String createJsonKeyForFiles(List<WorkspaceUploaderItem> fakeFiles){
|
||||
|
@ -308,7 +309,8 @@ public class MultipleDilaogUploadStream extends DialogUploadStream{
|
|||
|
||||
/**
|
||||
* Gets the files selected.
|
||||
* @param the tagID
|
||||
*
|
||||
* @param tagId the tag id
|
||||
* @param fileDelimiter the file delimiter
|
||||
* @return the files selected
|
||||
*/
|
||||
|
@ -324,4 +326,24 @@ public class MultipleDilaogUploadStream extends DialogUploadStream{
|
|||
}
|
||||
return out;
|
||||
}-*/;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#addWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
|
||||
*/
|
||||
@Override
|
||||
public void addWorkspaceUploadNotificationListener(
|
||||
WorskpaceUploadNotificationListener handler) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#removeWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeWorkspaceUploadNotificationListener(
|
||||
WorskpaceUploadNotificationListener handler) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEvent;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEventHandler;
|
||||
|
@ -42,7 +45,7 @@ public class UploaderMonitor {
|
|||
private MonitorPanel monitorPanel = new MonitorPanel(eventBus);
|
||||
private static Map<String, Timer> mapTimer = new HashMap<String, Timer>();
|
||||
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
|
||||
|
||||
private static List<WorskpaceUploadNotificationListener> listenersUpload = new ArrayList<WorskpaceUploadNotificationListener>();
|
||||
/**
|
||||
* Gets the single instance of UploaderMonitor.
|
||||
*
|
||||
|
@ -57,7 +60,7 @@ public class UploaderMonitor {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Bind events.
|
||||
*/
|
||||
private static void bindEvents() {
|
||||
|
||||
|
@ -104,33 +107,11 @@ public class UploaderMonitor {
|
|||
text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
|
||||
html.setHTML(text);
|
||||
deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
}
|
||||
|
||||
// Timer timer = mapTimer.get(deleteTimerEvent.getClientUploadKey());
|
||||
// GWT.log("Delete timer "+timer);
|
||||
// if(timer!=null && timer.isRunning()){
|
||||
// timer.cancel();
|
||||
// mapTimer.put(deleteTimerEvent.getClientUploadKey(), null);
|
||||
// }
|
||||
//
|
||||
// SubmitEvent submitEvent = mapSubmitEvent.get(deleteTimerEvent.getClientUploadKey());
|
||||
// GWT.log("Delete SubmitEvent "+submitEvent);
|
||||
// if(submitEvent!=null){
|
||||
// submitEvent.cancel();
|
||||
// mapSubmitEvent.put(deleteTimerEvent.getClientUploadKey(), null);
|
||||
// }
|
||||
|
||||
// DialogBox dialog = mapDialog.get(deleteTimerEvent.getClientUploadKey());
|
||||
// GWT.log("Delete dialog "+dialog);
|
||||
// if(dialog!=null){
|
||||
//// dialog.setVisible(true);
|
||||
// dialog.hide();
|
||||
// mapDialog.put(deleteTimerEvent.getClientUploadKey(), null);
|
||||
// }
|
||||
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,6 +127,9 @@ public class UploaderMonitor {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show monitor.
|
||||
*/
|
||||
public void showMonitor(){
|
||||
if(!dialogUploadMonitor.isShowing())
|
||||
dialogUploadMonitor.center();
|
||||
|
@ -158,8 +142,6 @@ public class UploaderMonitor {
|
|||
*
|
||||
* @param uploader the uploader
|
||||
* @param fileName the file name
|
||||
* @param event
|
||||
* @param dialog
|
||||
*/
|
||||
public void addNewSubmit(WorkspaceUploaderItem uploader, String fileName){
|
||||
if(!dialogUploadMonitor.isShowing())
|
||||
|
@ -169,31 +151,34 @@ public class UploaderMonitor {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Poll workspace uploader id.
|
||||
* Poll workspace uploader.
|
||||
*
|
||||
* @param uploaderId the uploader id
|
||||
* @param workspaceUploaderItem the workspace uploader item
|
||||
*/
|
||||
public void pollWorkspaceUploaderId(final String uploaderId){
|
||||
public void pollWorkspaceUploader(final WorkspaceUploaderItem workspaceUploaderItem){
|
||||
|
||||
Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(uploaderId, new AsyncCallback<WorkspaceUploaderItem>() {
|
||||
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploaderItem.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(WorkspaceUploaderItem result) {
|
||||
// GWT.log("onSuccess: "+result.toString());
|
||||
synchronized(this){
|
||||
Timer tmn = mapTimer.get(uploaderId);
|
||||
Timer tmn = mapTimer.get(workspaceUploaderItem);
|
||||
if(tmn!=null && tmn.isRunning()){
|
||||
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
|
||||
mapTimer.remove(tmn);
|
||||
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
// new DialogResult(null, "Upload Completed!!", result.getStatusDescription()).center();
|
||||
cancel();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
mapTimer.remove(tmn);
|
||||
notifyUploadError(result.getFile().getParentId(), null, null);
|
||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||
cancel();
|
||||
}
|
||||
|
@ -209,13 +194,76 @@ public class UploaderMonitor {
|
|||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
GWT.log("onFailure: "+caught.getMessage());
|
||||
notifyUploadError(workspaceUploaderItem.getFile().getParentId(), null, caught);
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
mapTimer.put(uploaderId, timer);
|
||||
mapTimer.put(workspaceUploaderItem.getClientUploadKey(), timer);
|
||||
timer.scheduleRepeating(2000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify upload completed.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private static void notifyUploadCompleted(String parentId, String itemId){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadCompleted(parentId, itemId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload aborted.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private static void notifyUploadAborted(String parentId, String itemId){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadAborted(parentId, itemId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload error.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param t the t
|
||||
*/
|
||||
private static void notifyUploadError(String parentId, String itemId, Throwable t){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onError(parentId, itemId, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void addWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
this.listenersUpload.add(handler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void removeWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
try {
|
||||
this.listenersUpload.remove(handler);
|
||||
} catch (Exception e) {
|
||||
// SILENT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -542,7 +542,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
WorkspaceUploaderItem workspaceUploader = new WorkspaceUploaderItem(clientUploadKey);
|
||||
workspaceUploader.setClientUploadKey(clientUploadKey);
|
||||
//Create File
|
||||
WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(folderParentId, fileName);
|
||||
WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(folderParentId, null, fileName);
|
||||
workspaceUploader.setFile(wsUploadFile);
|
||||
return workspaceUploader;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ public class WorkspaceUploaderMng {
|
|||
logger.debug("HL file "+createdItem.getName() + " uploaded correctly in "+destinationFolder.getPath());
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
||||
workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly");
|
||||
workspaceUploader.getFile().setItemId(createdItem.getId()); //SET HL ID
|
||||
workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID
|
||||
WorkspaceUploadServletStream.notifyUploadInSharedFolder(httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
|
||||
}else{
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
|
|
@ -19,6 +19,7 @@ public class WorkspaceUploadFile implements Serializable{
|
|||
|
||||
private String parentId;
|
||||
private String fileName;
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -31,13 +32,22 @@ public class WorkspaceUploadFile implements Serializable{
|
|||
* @param parentId
|
||||
* @param fileName
|
||||
*/
|
||||
public WorkspaceUploadFile(String parentId, String fileName) {
|
||||
public WorkspaceUploadFile(String parentId, String itemId, String fileName) {
|
||||
super();
|
||||
this.parentId = parentId;
|
||||
this.itemId = itemId;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param itemId the itemId to set
|
||||
*/
|
||||
public void setItemId(String itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the parentId
|
||||
*/
|
||||
|
@ -59,6 +69,22 @@ public class WorkspaceUploadFile implements Serializable{
|
|||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the itemId
|
||||
*/
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName the fileName to set
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -69,17 +95,10 @@ public class WorkspaceUploadFile implements Serializable{
|
|||
int hash = 31;
|
||||
hash = hash * 13 + (parentId == null ? 0 : parentId.hashCode());
|
||||
hash = hash * 17 + (fileName == null ? 0 : fileName.hashCode());
|
||||
hash = hash * 19 + (itemId == null ? 0 : itemId.hashCode());
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName the fileName to set
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@ -90,6 +109,8 @@ public class WorkspaceUploadFile implements Serializable{
|
|||
builder.append(parentId);
|
||||
builder.append(", fileName=");
|
||||
builder.append(fileName);
|
||||
builder.append(", itemId=");
|
||||
builder.append(itemId);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue